FileDocCategorySizeDatePackage
AndroidTestRunner.javaAPI DocAndroid 5.1 API8945Thu Mar 12 22:22:42 GMT 2015android.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
private android.os.PerformanceCollector.PerformanceResultsWriter
mPerfWriter
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 {
            Constructor c = testClass.getConstructor();
            return newSingleTestMethod(testClass, testMethodName, c);
        } catch (NoSuchMethodException e) {
        }

        try {
            Constructor c = testClass.getConstructor(String.class);
            return newSingleTestMethod(testClass, testMethodName, c, testMethodName);
        } catch (NoSuchMethodException e) {
        }

        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;
    
private junit.framework.TestCasenewSingleTestMethod(java.lang.Class testClass, java.lang.String testMethodName, java.lang.reflect.Constructor constructor, java.lang.Object args)

        try {
            TestCase testCase = (TestCase) constructor.newInstance(args);
            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());
        } catch (IllegalArgumentException e) {
            runFailed("Illegal argument passed to constructor. Class: " + testClass.getName());
        } catch (InvocationTargetException e) {
            runFailed("Constructor thew an exception. Class: " + testClass.getName());
        }
        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);
        }

        Context testContext = mInstrumentation == null ? mContext : mInstrumentation.getContext();
        for (TestCase testCase : mTestCases) {
            setContextIfAndroidTestCase(testCase, mContext, testContext);
            setInstrumentationIfInstrumentationTestCase(testCase, mInstrumentation);
            setPerformanceWriterIfPerformanceCollectorTestCase(testCase, mPerfWriter);
            testCase.run(mTestResult);
        }
    
public voidsetContext(android.content.Context context)

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

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

deprecated
Incorrect spelling, use {@link #setInstrumentation(android.app.Instrumentation)} instead.

        setInstrumentation(instrumentation);
    
public voidsetInstrumentation(android.app.Instrumentation instrumentation)

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

        if (InstrumentationTestCase.class.isAssignableFrom(test.getClass())) {
            ((InstrumentationTestCase) test).injectInstrumentation(instrumentation);
        }
    
public voidsetPerformanceResultsWriter(android.os.PerformanceCollector.PerformanceResultsWriter writer)
{@hide} Pending approval for public API.

        mPerfWriter = writer;
    
private voidsetPerformanceWriterIfPerformanceCollectorTestCase(junit.framework.Test test, android.os.PerformanceCollector.PerformanceResultsWriter writer)

        if (PerformanceCollectorTestCase.class.isAssignableFrom(test.getClass())) {
            ((PerformanceCollectorTestCase) test).setPerformanceResultsWriter(writer);
        }
    
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)