InstrumentationRunnerValidatorpublic class InstrumentationRunnerValidator extends Object Provides validation for Android instrumentation test runner |
Fields Summary |
---|
private final org.eclipse.jdt.core.IJavaProject | mJavaProject | private String[] | mInstrumentationNames | private boolean | mHasRunnerLibrary | static final String | INSTRUMENTATION_OK |
Constructors Summary |
---|
InstrumentationRunnerValidator(org.eclipse.jdt.core.IJavaProject javaProject)Initializes the InstrumentationRunnerValidator.
mJavaProject = javaProject;
try {
AndroidManifestParser manifestParser = AndroidManifestParser.parse(javaProject,
null /* errorListener */, true /* gatherData */, false /* markErrors */);
init(manifestParser);
} catch (CoreException e) {
AdtPlugin.printErrorToConsole(javaProject.getProject(), "ERROR: Failed to parse %1$s",
AndroidConstants.FN_ANDROID_MANIFEST);
}
| InstrumentationRunnerValidator(org.eclipse.core.resources.IProject project)Initializes the InstrumentationRunnerValidator.
this(BaseProjectHelper.getJavaProject(project));
| InstrumentationRunnerValidator(org.eclipse.jdt.core.IJavaProject javaProject, com.android.ide.eclipse.common.project.AndroidManifestParser manifestParser)Initializes the InstrumentationRunnerValidator with an existing {@link AndroidManifestParser}
mJavaProject = javaProject;
init(manifestParser);
|
Methods Summary |
---|
java.lang.String[] | getInstrumentationNames()Return the set of instrumentation names for the Android project.
return mInstrumentationNames;
| java.lang.String | getValidInstrumentationTestRunner()Helper method to get the first instrumentation that can be used as a test runner.
for (String instrumentation : getInstrumentationNames()) {
if (validateInstrumentationRunner(instrumentation) == INSTRUMENTATION_OK) {
return instrumentation;
}
}
return null;
| private boolean | hasTestRunnerLibrary(com.android.ide.eclipse.common.project.AndroidManifestParser manifestParser)Helper method to determine if given manifest has a AndroidConstants.LIBRARY_TEST_RUNNER
library reference
for (String lib : manifestParser.getUsesLibraries()) {
if (lib.equals(AndroidConstants.LIBRARY_TEST_RUNNER)) {
return true;
}
}
return false;
| private void | init(com.android.ide.eclipse.common.project.AndroidManifestParser manifestParser)
Instrumentation[] instrumentations = manifestParser.getInstrumentations();
mInstrumentationNames = new String[instrumentations.length];
for (int i = 0; i < instrumentations.length; i++) {
mInstrumentationNames[i] = instrumentations[i].getName();
}
mHasRunnerLibrary = hasTestRunnerLibrary(manifestParser);
| java.lang.String | validateInstrumentationRunner(java.lang.String instrumentation)Helper method to determine if specified instrumentation can be used as a test runner
if (!mHasRunnerLibrary) {
return String.format("The application does not declare uses-library %1$s",
AndroidConstants.LIBRARY_TEST_RUNNER);
}
// check if this instrumentation is the standard test runner
if (!instrumentation.equals(AndroidConstants.CLASS_INSTRUMENTATION_RUNNER)) {
// check if it extends the standard test runner
String result = BaseProjectHelper.testClassForManifest(mJavaProject,
instrumentation, AndroidConstants.CLASS_INSTRUMENTATION_RUNNER, true);
if (result != BaseProjectHelper.TEST_CLASS_OK) {
return String.format("The instrumentation runner must be of type %s",
AndroidConstants.CLASS_INSTRUMENTATION_RUNNER);
}
}
return INSTRUMENTATION_OK;
|
|