Search in sources :

Example 31 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by DirtyUnicorns.

the class AndroidTestRunnerTest method testSetTestClassWithTestSuite.

public void testSetTestClassWithTestSuite() throws Exception {
    mAndroidTestRunner.setTestClassName(SampleTestSuite.class.getName(), null);
    List<TestCase> testCases = mAndroidTestRunner.getTestCases();
    List<String> testNames = Lists.newArrayList();
    for (TestCase testCase : testCases) {
        testNames.add(testCase.getName());
    }
    assertEquals(Arrays.asList("testOne", "testOne", "testTwo"), testNames);
}
Also used : TestCase(junit.framework.TestCase)

Example 32 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by DirtyUnicorns.

the class AndroidTestRunnerTest method testRunTestWithAndroidTestCaseInNestedSuite.

public void testRunTestWithAndroidTestCaseInNestedSuite() throws Exception {
    mAndroidTestRunner.setTestClassName(AndroidTestCaseTestSuite.class.getName(), null);
    TestListenerStub testListenerStub = new TestListenerStub();
    mAndroidTestRunner.addTestListener(testListenerStub);
    mAndroidTestRunner.runTest();
    assertTrue(testListenerStub.saw("testOneAndroid"));
    List<TestCase> testCases = mAndroidTestRunner.getTestCases();
    for (TestCase testCase : testCases) {
        assertSame(mStubContext, ((AndroidTestCase) testCase).getContext());
    }
}
Also used : TestCase(junit.framework.TestCase)

Example 33 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by DirtyUnicorns.

the class AndroidTestRunner method runTest.

public void runTest(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);
    }
}
Also used : Context(android.content.Context) TestCase(junit.framework.TestCase) TestListener(junit.framework.TestListener)

Example 34 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by DirtyUnicorns.

the class AndroidTestRunner method setTestClassName.

@SuppressWarnings("unchecked")
public void setTestClassName(String testClassName, 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);
    }
}
Also used : TestCase(junit.framework.TestCase)

Example 35 with TestCase

use of junit.framework.TestCase in project android_frameworks_base by DirtyUnicorns.

the class AndroidTestRunner method newSingleTestMethod.

private TestCase newSingleTestMethod(Class testClass, String testMethodName, Constructor constructor, 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;
}
Also used : TestCase(junit.framework.TestCase) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TestCase (junit.framework.TestCase)129 TestSuite (junit.framework.TestSuite)36 Test (junit.framework.Test)22 TestListener (junit.framework.TestListener)17 TestResult (junit.framework.TestResult)13 ArrayList (java.util.ArrayList)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 AssertionFailedError (junit.framework.AssertionFailedError)10 Constructor (java.lang.reflect.Constructor)8 Enumeration (java.util.Enumeration)6 Context (android.content.Context)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5 Bundle (android.os.Bundle)5 HandlerThread (android.os.HandlerThread)5 ShellUiAutomatorBridge (com.android.uiautomator.core.ShellUiAutomatorBridge)5 Tracer (com.android.uiautomator.core.Tracer)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5 Field (java.lang.reflect.Field)5 HashSet (java.util.HashSet)5