FileDocCategorySizeDatePackage
RemoteAdtTestRunner.javaAPI DocAndroid 1.5 API8782Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt.launch.junit.runtime

RemoteAdtTestRunner

public 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.

see
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner for more details on the protocol

Fields Summary
private AndroidJUnitLaunchInfo
mLaunchInfo
private org.eclipse.jdt.internal.junit.runner.TestExecution
mExecution
Constructors Summary
Methods Summary
protected voidinit(java.lang.String[] args, AndroidJUnitLaunchInfo launchInfo)
Initialize the JDT JUnit test runner parameters from the {@code args}.

param
args name-value pair of arguments to pass to parent JUnit runner.
param
launchInfo the Android specific test launch info

        defaultInit(args);
        mLaunchInfo = launchInfo;
    
private voidnotifyTestRunEnded(long elapsedTime)

        // copy from parent - not ideal, but method is private
        sendMessage(MessageIds.TEST_RUN_END + elapsedTime);
        flush();
        //shutDown();
    
private voidreportError(java.lang.String errorMessage)

param
errorMessage

        AdtPlugin.printErrorToConsole(mLaunchInfo.getProject(), 
                String.format("Test run failed: %s", errorMessage));
        // is this needed?
        //notifyTestRunStopped(-1);
    
public voidrunTests(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:

  1. The total number of tests to be executed.
  2. 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.
  3. 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.
  4. 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.

param
testClassNames ignored - the AndroidJUnitLaunchInfo will be used to determine which tests to run.
param
testName ignored
param
execution used to report test progress

        // 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 voidrunTests(java.lang.String[] programArgs, AndroidJUnitLaunchInfo junitInfo)
Main entry method to run tests

param
programArgs JDT JUnit program arguments to be processed by parent
param
junitInfo the {@link AndroidJUnitLaunchInfo} containing info about this test ru

        init(programArgs, junitInfo);
        run();
    
protected voidstop()

        if (mExecution != null) {
            mExecution.stop();
        }    
    
public voidterminate()
Stop the current test run.

        stop();