FileDocCategorySizeDatePackage
AndroidTestRunnerTest.javaAPI DocAndroid 1.5 API10138Wed May 06 22:42:02 BST 2009android.test

AndroidTestRunnerTest

public class AndroidTestRunnerTest extends TestCase
Unit tests for {@link AndroidTestRunner}

Fields Summary
private AndroidTestRunner
mAndroidTestRunner
private StubContext
mStubContext
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        mStubContext = new StubContext(getClass().getClassLoader());

        mAndroidTestRunner = new AndroidTestRunner();
        mAndroidTestRunner.setContext(mStubContext);
    
public voidtestLoadNoTestCases()

        mAndroidTestRunner.setTestClassName(TestSuite.class.getName(), null);

        List<TestCase> testCases = mAndroidTestRunner.getTestCases();
        assertNotNull(testCases);
        assertEquals(1, testCases.size());
        assertEquals("warning", testCases.get(0).getName());
        assertEquals(TestSuite.class.getSimpleName(), mAndroidTestRunner.getTestClassName());
    
public voidtestRunSingleTestMethod()

        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);
    
public voidtestRunSkipExecution()

        String testMethodName = "testFail";
        mAndroidTestRunner.setTestClassName(
                OnePassOneErrorOneFailTestCase.class.getName(), testMethodName);
        
        TestListenerStub testListenerStub = new TestListenerStub();
        mAndroidTestRunner.addTestListener(testListenerStub);
        
        // running the failing test should pass - ie as if its not run
        mAndroidTestRunner.runTest();
        
        assertTrue(testListenerStub.saw("testFail"));
    
public voidtestRunTest()

        mAndroidTestRunner.setTestClassName(OneTestTestCase.class.getName(), null);

        TestListenerStub testListenerStub = new TestListenerStub();
        mAndroidTestRunner.addTestListener(testListenerStub);

        mAndroidTestRunner.runTest();

        assertTrue(testListenerStub.saw("testOne"));
    
public voidtestRunTestWithAndroidTestCase()

        mAndroidTestRunner.setTestClassName(
                OneAndroidTestTestCase.class.getName(), "testOneAndroid");

        TestListenerStub testListenerStub = new TestListenerStub();
        mAndroidTestRunner.addTestListener(testListenerStub);

        assertNull(((AndroidTestCase) mAndroidTestRunner.getTestCases().get(0)).getContext());

        mAndroidTestRunner.runTest();

        assertTrue(testListenerStub.saw("testOneAndroid"));
        assertSame(mStubContext,
                ((AndroidTestCase) mAndroidTestRunner.getTestCases().get(0)).getContext());
    
public voidtestRunTestWithAndroidTestCaseInNestedSuite()

        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());
        }
    
public voidtestRunTestWithAndroidTestCaseInSuite()

        mAndroidTestRunner.setTestClassName(OneAndroidTestTestCase.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());
        }
    
public voidtestRunTestWithNullListener()

        mAndroidTestRunner.setTestClassName(OneTestTestCase.class.getName(), null);

        mAndroidTestRunner.addTestListener(null);
        try {
            mAndroidTestRunner.runTest();
        } catch (NullPointerException e) {
            fail("Should not add a null TestListener");
        }
    
public voidtestSetTestClassInvalidClass()

        try {
            mAndroidTestRunner.setTestClassName("class.that.does.not.exist", null);
            fail("expected exception not thrown");
        } catch (RuntimeException e) {
            // expected
        }
    
public voidtestSetTestClassWithTestSuite()

        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);
    
public voidtestSetTestClassWithTestSuiteProvider()

        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);
    
public voidtestSetTestSuiteWithOneTestCase()

        mAndroidTestRunner.setTestClassName(OneTestTestCase.class.getName(), null);

        List<TestCase> testCases = mAndroidTestRunner.getTestCases();
        assertNotNull(testCases);
        assertEquals(1, testCases.size());
        assertEquals("testOne", testCases.get(0).getName());
        assertEquals(OneTestTestCase.class.getSimpleName(), mAndroidTestRunner.getTestClassName());