Search in sources :

Example 56 with Test

use of junit.framework.Test 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 57 with Test

use of junit.framework.Test 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 58 with Test

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

the class InstrumentationTestRunnerTest method assertTestRunnerCalledWithExpectedParameters.

private void assertTestRunnerCalledWithExpectedParameters(String expectedTestClassName, String expectedTestMethodName) {
    Test test = mStubAndroidTestRunner.getTest();
    assertContentsInOrder(ListTestCaseNames.getTestNames((TestSuite) test), new TestDescriptor(expectedTestClassName, expectedTestMethodName));
    assertTrue(mInstrumentationTestRunner.isStarted());
    assertFalse(mInstrumentationTestRunner.isFinished());
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest) TestDescriptor(android.test.suitebuilder.ListTestCaseNames.TestDescriptor)

Example 59 with Test

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

the class TestCaseUtilTest method testCreateTestForTestCaseWithSuiteMethod.

public void testCreateTestForTestCaseWithSuiteMethod() throws Exception {
    Test test = TestCaseUtil.createTestSuite(OneTestTestCaseWithSuite.class);
    assertEquals(1, test.countTestCases());
}
Also used : Test(junit.framework.Test)

Example 60 with Test

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

the class TestCaseUtilTest method testCreateTestForTestCase.

public void testCreateTestForTestCase() throws Exception {
    Test test = TestCaseUtil.createTestSuite(OneTestTestCase.class);
    assertEquals(1, test.countTestCases());
}
Also used : Test(junit.framework.Test)

Aggregations

Test (junit.framework.Test)114 TestSuite (junit.framework.TestSuite)45 TestCase (junit.framework.TestCase)22 ArrayList (java.util.ArrayList)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Method (java.lang.reflect.Method)12 AssertionFailedError (junit.framework.AssertionFailedError)12 TestListener (junit.framework.TestListener)11 TestResult (junit.framework.TestResult)11 TestDescriptor (android.test.suitebuilder.ListTestCaseNames.TestDescriptor)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 Enumeration (java.util.Enumeration)10 RepeatedTest (junit.extensions.RepeatedTest)7 AndroidTestRunner (android.test.AndroidTestRunner)5 Field (java.lang.reflect.Field)5 List (java.util.List)5 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)2 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)2 GridAbstractTest (org.apache.ignite.testframework.junits.GridAbstractTest)2