RemoteAdtTestRunnerpublic class RemoteAdtTestRunner extends org.eclipse.jdt.internal.junit.runner.RemoteTestRunner Supports Eclipse JUnit execution of Android tests.
Communicates back to a Eclipse JDT JUnit client via a socket connection. |
Fields Summary |
---|
private AndroidJUnitLaunchInfo | mLaunchInfo | private org.eclipse.jdt.internal.junit.runner.TestExecution | mExecution |
Methods Summary |
---|
protected void | init(java.lang.String[] args, AndroidJUnitLaunchInfo launchInfo)Initialize the JDT JUnit test runner parameters from the {@code args}.
defaultInit(args);
mLaunchInfo = launchInfo;
| private void | notifyTestRunEnded(long elapsedTime)
// copy from parent - not ideal, but method is private
sendMessage(MessageIds.TEST_RUN_END + elapsedTime);
flush();
//shutDown();
| private void | reportError(java.lang.String errorMessage)
AdtPlugin.printErrorToConsole(mLaunchInfo.getProject(),
String.format("Test run failed: %s", errorMessage));
// is this needed?
//notifyTestRunStopped(-1);
| public void | runTests(java.lang.String[] testClassNames, java.lang.String testName, org.eclipse.jdt.internal.junit.runner.TestExecution execution)Runs a set of tests, and reports back results using parent class.
JDT Unit expects to be sent data in the following sequence:
- The total number of tests to be executed.
- The test 'tree' data about the tests to be executed, which is composed of the set of
test class names, the number of tests in each class, and the names of each test in the
class.
- The test execution result for each test method. Expects individual notifications of
the test execution start, any failures, and the end of the test execution.
- The end of the test run, with its elapsed time.
In order to satisfy this, this method performs two actual Android instrumentation runs.
The first is a 'log only' run that will collect the test tree data, without actually
executing the tests, and send it back to JDT JUnit. The second is the actual test execution,
whose results will be communicated back in real-time to JDT JUnit.
// hold onto this execution reference so it can be used to report test progress
mExecution = execution;
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(mLaunchInfo.getAppPackage(),
mLaunchInfo.getRunner(), mLaunchInfo.getDevice());
if (mLaunchInfo.getTestClass() != null) {
if (mLaunchInfo.getTestMethod() != null) {
runner.setMethodName(mLaunchInfo.getTestClass(), mLaunchInfo.getTestMethod());
} else {
runner.setClassName(mLaunchInfo.getTestClass());
}
}
if (mLaunchInfo.getTestPackage() != null) {
runner.setTestPackageName(mLaunchInfo.getTestPackage());
}
// set log only to first collect test case info, so Eclipse has correct test case count/
// tree info
runner.setLogOnly(true);
TestCollector collector = new TestCollector();
runner.run(collector);
if (collector.getErrorMessage() != null) {
// error occurred during test collection.
reportError(collector.getErrorMessage());
// abort here
notifyTestRunEnded(0);
return;
}
notifyTestRunStarted(collector.getTestCaseCount());
collector.sendTrees(this);
// now do real execution
runner.setLogOnly(false);
if (mLaunchInfo.isDebugMode()) {
runner.setDebug(true);
}
runner.run(new TestRunListener());
| public void | runTests(java.lang.String[] programArgs, AndroidJUnitLaunchInfo junitInfo)Main entry method to run tests
init(programArgs, junitInfo);
run();
| protected void | stop()
if (mExecution != null) {
mExecution.stop();
}
| public void | terminate()Stop the current test run.
stop();
|
|