Search in sources :

Example 26 with TestCase

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

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

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

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)

Example 28 with TestCase

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

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

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

the class SmokeTestRunner method getAllTests.

/**
     * Returns a single testcase for each app to launch
     */
@Override
public TestSuite getAllTests() {
    final TestSuite suite = new TestSuite(SUITE_NAME);
    final PackageManager pm = getTargetContext().getPackageManager();
    final List<ResolveInfo> apps = ProcessErrorsTest.getLauncherActivities(pm);
    final TestCase setupTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testSetUpConditions();
        }
    };
    setupTest.setName("testSetUpConditions");
    suite.addTest(setupTest);
    final TestCase postBootTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testNoProcessErrorsAfterBoot();
        }
    };
    postBootTest.setName("testNoProcessErrorsAfterBoot");
    suite.addTest(postBootTest);
    for (final ResolveInfo app : apps) {
        final TestCase appTest = new ProcessErrorsTest() {

            @Override
            public void runTest() throws Exception {
                final Set<ProcessError> errSet = new HashSet<ProcessError>();
                final Collection<ProcessError> errProcs = runOneActivity(app);
                if (errProcs != null) {
                    errSet.addAll(errProcs);
                }
                if (!errSet.isEmpty()) {
                    fail(String.format("Got %d errors:\n%s", errSet.size(), reportWrappedListContents(errSet)));
                }
            }
        };
        appTest.setName(app.activityInfo.name);
        suite.addTest(appTest);
    }
    final TestCase asyncErrorTest = new ProcessErrorsTest() {

        @Override
        public void runTest() throws Exception {
            testZZReportAsyncErrors();
        }
    };
    asyncErrorTest.setName("testAsynchronousErrors");
    suite.addTest(asyncErrorTest);
    return suite;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) TestSuite(junit.framework.TestSuite) PackageManager(android.content.pm.PackageManager) TestCase(junit.framework.TestCase) HashSet(java.util.HashSet)

Example 30 with TestCase

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

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)

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