Search in sources :

Example 41 with TestCase

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

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

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

the class TestSuiteBuilder method build.

/**
     * Call this method once you've configured your builder as desired.
     *
     * @return The suite containing the requested tests.
     */
public final TestSuite build() {
    rootSuite = new TestSuite(getSuiteName());
    // Keep track of current class so we know when to create a new sub-suite.
    currentClassname = null;
    try {
        for (TestMethod test : testGrouping.getTests()) {
            if (satisfiesAllPredicates(test)) {
                addTest(test);
            }
        }
        if (testCases.size() > 0) {
            for (TestCase testCase : testCases) {
                if (satisfiesAllPredicates(new TestMethod(testCase))) {
                    addTest(testCase);
                }
            }
        }
    } catch (Exception exception) {
        Log.i("TestSuiteBuilder", "Failed to create test.", exception);
        TestSuite suite = new TestSuite(getSuiteName());
        suite.addTest(new FailedToCreateTests(exception));
        return suite;
    }
    return rootSuite;
}
Also used : TestSuite(junit.framework.TestSuite) TestCase(junit.framework.TestCase)

Example 43 with TestCase

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

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

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

the class TestCaseUtilTest method testGetTestCaseNamesForTestCaseWithSuiteMethod.

public void testGetTestCaseNamesForTestCaseWithSuiteMethod() throws Exception {
    TestCase testCase = new OneTestTestCaseWithSuite();
    List<String> testCaseNames = TestCaseUtil.getTestCaseNames(testCase, false);
    assertEquals(1, testCaseNames.size());
    assertTrue(testCaseNames.get(0).endsWith("testOne"));
}
Also used : TestCase(junit.framework.TestCase)

Example 45 with TestCase

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

the class ListTestCaseNames method getTestNames.

/** 
     * Returns a list of test class and method names for each TestCase in suite.  
     */
public static List<TestDescriptor> getTestNames(TestSuite suite) {
    List<Test> tests = Collections.<Test>list(suite.tests());
    ArrayList<TestDescriptor> testNames = new ArrayList<TestDescriptor>();
    for (Test test : tests) {
        if (test instanceof TestCase) {
            String className = test.getClass().getName();
            String testName = ((TestCase) test).getName();
            testNames.add(new TestDescriptor(className, testName));
        } else if (test instanceof TestSuite) {
            testNames.addAll(getTestNames((TestSuite) test));
        }
    }
    return testNames;
}
Also used : TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) TestCase(junit.framework.TestCase) ArrayList(java.util.ArrayList)

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