FileDocCategorySizeDatePackage
AndroidTestRunner.javaAPI DocAndroid 1.5 API6877Wed May 06 22:42:02 BST 2009android.test

AndroidTestRunner

public class AndroidTestRunner extends BaseTestRunner

Fields Summary
private TestResult
mTestResult
private String
mTestClassName
private List
mTestCases
private android.content.Context
mContext
private boolean
mSkipExecution
private List
mTestListeners
private android.app.Instrumentation
mInstrumentation
Constructors Summary
Methods Summary
public voidaddTestListener(junit.framework.TestListener testListener)

        if (testListener != null) {
            mTestListeners.add(testListener);
        }
    
private junit.framework.TestCasebuildSingleTestMethod(java.lang.Class testClass, java.lang.String testMethodName)

        try {
            TestCase testCase = (TestCase) testClass.newInstance();
            testCase.setName(testMethodName);
            return testCase;
        } catch (IllegalAccessException e) {
            runFailed("Could not access test class. Class: " + testClass.getName());
        } catch (InstantiationException e) {
            runFailed("Could not instantiate test class. Class: " + testClass.getName());
        }

        return null;
    
public voidclearTestListeners()

        mTestListeners.clear();
    
protected junit.framework.TestResultcreateTestResult()

        if (mSkipExecution) {
            return new NoExecTestResult();
        }
        return new TestResult();
    
private junit.framework.TestgetTest(java.lang.Class clazz)

        if (TestSuiteProvider.class.isAssignableFrom(clazz)) {
            try {
                TestSuiteProvider testSuiteProvider =
                        (TestSuiteProvider) clazz.getConstructor().newInstance();
                return testSuiteProvider.getTestSuite();
            } catch (InstantiationException e) {
                runFailed("Could not instantiate test suite provider. Class: " + clazz.getName());
            } catch (IllegalAccessException e) {
                runFailed("Illegal access of test suite provider. Class: " + clazz.getName());
            } catch (InvocationTargetException e) {
                runFailed("Invocation exception test suite provider. Class: " + clazz.getName());
            } catch (NoSuchMethodException e) {
                runFailed("No such method on test suite provider. Class: " + clazz.getName());
            }
        }
        return getTest(clazz.getName());
    
public java.util.ListgetTestCases()

        return mTestCases;
    
public java.lang.StringgetTestClassName()

        return mTestClassName;
    
public junit.framework.TestResultgetTestResult()

        return mTestResult;
    
protected java.lang.ClassloadSuiteClass(java.lang.String suiteClassName)

        return mContext.getClassLoader().loadClass(suiteClassName);
    
private java.lang.ClassloadTestClass(java.lang.String testClassName)

        try {
            return (Class<? extends Test>) mContext.getClassLoader().loadClass(testClassName);
        } catch (ClassNotFoundException e) {
            runFailed("Could not find test class. Class: " + testClassName);
        }
        return null;
    
protected voidrunFailed(java.lang.String message)

        throw new RuntimeException(message);
    
public voidrunTest()

        runTest(createTestResult());
    
public voidrunTest(junit.framework.TestResult testResult)

        mTestResult = testResult;

        for (TestListener testListener : mTestListeners) {
            mTestResult.addListener(testListener);
        }

        for (TestCase testCase : mTestCases) {
            setContextIfAndroidTestCase(testCase, mContext);
            setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
            testCase.run(mTestResult);
        }
    
public voidsetContext(android.content.Context context)

        mContext = context;
    
private voidsetContextIfAndroidTestCase(junit.framework.Test test, android.content.Context context)

        if (AndroidTestCase.class.isAssignableFrom(test.getClass())) {
            ((AndroidTestCase) test).setContext(context);
        }
    
public voidsetInstrumentaiton(android.app.Instrumentation instrumentation)

        mInstrumentation = instrumentation;
    
private voidsetInstrumentationIfInstrumentationTestCase(junit.framework.Test test, android.app.Instrumentation instrumentation)

        if (InstrumentationTestCase.class.isAssignableFrom(test.getClass())) {
            ((InstrumentationTestCase) test).injectInsrumentation(instrumentation);
        }
    
voidsetSkipExecution(boolean skip)

        mSkipExecution = skip;
    
public voidsetTest(junit.framework.Test test)

        setTest(test, test.getClass());
    
private voidsetTest(junit.framework.Test test, java.lang.Class testClass)

        mTestCases = (List<TestCase>) TestCaseUtil.getTests(test, true);
        if (TestSuite.class.isAssignableFrom(testClass)) {
            mTestClassName = TestCaseUtil.getTestName(test);
        } else {
            mTestClassName = testClass.getSimpleName();
        }
    
public voidsetTestClassName(java.lang.String testClassName, java.lang.String testMethodName)

        Class testClass = loadTestClass(testClassName);

        if (shouldRunSingleTestMethod(testMethodName, testClass)) {
            TestCase testCase = buildSingleTestMethod(testClass, testMethodName);
            mTestCases = Lists.newArrayList(testCase);
            mTestClassName = testClass.getSimpleName();
        } else {
            setTest(getTest(testClass), testClass);
        }
    
private booleanshouldRunSingleTestMethod(java.lang.String testMethodName, java.lang.Class testClass)

        return testMethodName != null && TestCase.class.isAssignableFrom(testClass);
    
public voidtestEnded(java.lang.String testName)

    
public voidtestFailed(int status, junit.framework.Test test, java.lang.Throwable t)

    
public voidtestStarted(java.lang.String testName)