Search in sources :

Example 81 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

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 82 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

the class TestCaseUtil method getTests.

private static List<? extends Test> getTests(Test test, boolean flatten, Set<Class<?>> seen) {
    List<Test> testCases = Lists.newArrayList();
    if (test != null) {
        Test workingTest = null;
        /*
             * If we want to run a single TestCase method only, we must not
             * invoke the suite() method, because we will run all test methods
             * of the class then.
             */
        if (test instanceof TestCase && ((TestCase) test).getName() == null) {
            workingTest = invokeSuiteMethodIfPossible(test.getClass(), seen);
        }
        if (workingTest == null) {
            workingTest = test;
        }
        if (workingTest instanceof TestSuite) {
            TestSuite testSuite = (TestSuite) workingTest;
            Enumeration enumeration = testSuite.tests();
            while (enumeration.hasMoreElements()) {
                Test childTest = (Test) enumeration.nextElement();
                if (flatten) {
                    testCases.addAll(getTests(childTest, flatten, seen));
                } else {
                    testCases.add(childTest);
                }
            }
        } else {
            testCases.add(workingTest);
        }
    }
    return testCases;
}
Also used : Enumeration(java.util.Enumeration) TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) TestCase(junit.framework.TestCase)

Example 83 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

the class ListTestCaseNames method getTestCaseNames.

public static List<String> getTestCaseNames(TestSuite suite) {
    // TODO: deprecate this method and move all callers to use getTestNames
    List<Test> tests = Collections.<Test>list(suite.tests());
    ArrayList<String> testCaseNames = new ArrayList<String>();
    for (Test test : tests) {
        if (test instanceof TestCase) {
            testCaseNames.add(((TestCase) test).getName());
        } else if (test instanceof TestSuite) {
            testCaseNames.addAll(getTestCaseNames((TestSuite) test));
        }
    }
    return testCaseNames;
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) TestCase(junit.framework.TestCase) ArrayList(java.util.ArrayList)

Example 84 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

the class AndroidTestRunnerTest method testSetTestClassWithTestSuiteProvider.

public void testSetTestClassWithTestSuiteProvider() throws Exception {
    mAndroidTestRunner.setTestClassName(SampleTestSuiteProvider.class.getName(), null);
    List<TestCase> testCases = mAndroidTestRunner.getTestCases();
    List<String> testNames = Lists.newArrayList();
    for (TestCase testCase : testCases) {
        testNames.add(testCase.getName());
    }
    // Use the test suite provided by the interface method rather than the static suite method.
    assertEquals(Arrays.asList("testOne"), testNames);
}
Also used : TestCase(junit.framework.TestCase)

Example 85 with TestCase

use of junit.framework.TestCase in project platform_frameworks_base by android.

the class AndroidTestRunnerTest method testRunSingleTestMethod.

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

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