Search in sources :

Example 1 with TestCase

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

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

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

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

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

the class TestMethod method instantiateTest.

@SuppressWarnings("unchecked")
private TestCase instantiateTest(Class testCaseClass, String testName) throws InvocationTargetException, IllegalAccessException, InstantiationException {
    Constructor[] constructors = testCaseClass.getConstructors();
    if (constructors.length == 0) {
        return instantiateTest(testCaseClass.getSuperclass(), testName);
    } else {
        for (Constructor constructor : constructors) {
            Class[] params = constructor.getParameterTypes();
            if (noargsConstructor(params)) {
                TestCase test = ((Constructor<? extends TestCase>) constructor).newInstance();
                // JUnit will run just the one test if you call
                // {@link TestCase#setName(String)}
                test.setName(testName);
                return test;
            } else if (singleStringConstructor(params)) {
                return ((Constructor<? extends TestCase>) constructor).newInstance(testName);
            }
        }
    }
    throw new RuntimeException("Unable to locate a constructor for " + testCaseClass.getName());
}
Also used : TestCase(junit.framework.TestCase) Constructor(java.lang.reflect.Constructor)

Example 4 with TestCase

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

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) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with TestCase

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

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)

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