FileDocCategorySizeDatePackage
TestSuiteBuilderTest.javaAPI DocAndroid 1.5 API8444Wed May 06 22:42:02 BST 2009android.test.suitebuilder

TestSuiteBuilderTest

public class TestSuiteBuilderTest extends TestCase

Fields Summary
private TestSuiteBuilder
testSuiteBuilder
Constructors Summary
Methods Summary
private voidassertContentsInOrder(java.util.List actual, java.lang.String source)

        String[] clonedSource = source.clone();
        assertEquals("Unexpected number of items.", clonedSource.length, actual.size());
        for (int i = 0; i < actual.size(); i++) {
            String actualItem = actual.get(i);
            String sourceItem = clonedSource[i];
            assertEquals("Unexpected item. Index: " + i, sourceItem, actualItem);
        }
    
private static java.lang.StringpackageFor(java.lang.Class clazz)

        String className = clazz.getName();
        return className.substring(0, className.lastIndexOf('."));
    
private android.test.suitebuilder.TestSuiteBuilderTest$SuiteExecutionRecorderrunSuite(TestSuiteBuilder builder)

        TestSuite suite = builder.build();
        SuiteExecutionRecorder recorder = new SuiteExecutionRecorder();
        TestResult result = new TestResult();
        result.addListener(recorder);
        suite.run(result);
        return recorder;
    
protected voidsetUp()

        super.setUp();
        testSuiteBuilder = new TestSuiteBuilder(getClass());
    
public voidtestExcludePackage()

        testSuiteBuilder.includePackages(packageFor(SimpleTest.class),
                packageFor(Level1Test.class)).excludePackages(packageFor(Level2Test.class));

        TestSuite testSuite = testSuiteBuilder.build();
        assertContentsInOrder(getTestCaseNames(testSuite),
                "testLevel1", "testAnotherOne", "testSimpleOne", "testSimpleTwo");
    
public voidtestIncludeAllPackagesUnderHere()
This test calls {@link OuterTest#buildTestsUnderHereRecursively()} to control the packages under test. The call to {@link TestSuiteBuilder#includeAllPackagesUnderHere()} is made from there so that only return the example tests.


        TestSuite testSuite = new OuterTest().buildTestsUnderHereRecursively();
        assertContentsInOrder(getTestCaseNames(testSuite),
                "testOuter", "testErrorOne", "testErrorTwo", "testFailOne", "testFailTwo",
                "testInstrumentation", "testLevel1", "testLevel2", "testAnotherOne",
                "testSimpleOne", "testSimpleTwo", "testNonSmoke", "testSmoke", "testSubclass",
                "testSuperclass", "testUnSuppressedMethod");
    
public voidtestShouldAddFailingTestsToSuite()

        testSuiteBuilder.includePackages(packageFor(FailingTest.class));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertTrue(recorder.failed("FailingTest.testFailOne"));
        assertTrue(recorder.failed("FailingTest.testFailTwo"));
    
public voidtestShouldAddTestsWithErrorsToSuite()

        testSuiteBuilder.includePackages(packageFor(ErrorTest.class));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertTrue(recorder.errored("ErrorTest.testErrorOne"));
        assertTrue(recorder.errored("ErrorTest.testErrorTwo"));
    
public voidtestShouldExcludeSuppressedTests()

        testSuiteBuilder.includePackages(packageFor(SuppressedTest.class));
        testSuiteBuilder.build();

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertEquals(1, recorder.testsSeen.size());
        assertTrue(recorder.passed("PartiallySuppressedTest.testUnSuppressedMethod"));
    
public voidtestShouldIncludeTestsInSubPackagesRecursively()

        testSuiteBuilder.includePackages(packageFor(Level1Test.class));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertTrue(recorder.passed("Level1Test.testLevel1"));
        assertTrue(recorder.passed("Level2Test.testLevel2"));
    
public voidtestShouldOnlyIncludeTestsThatSatisfyAllPredicates()

        testSuiteBuilder.includePackages(packageFor(SimpleTest.class))
                .addRequirements(testsWhoseNameContains("test"))
                .addRequirements(testsWhoseNameContains("Simple"))
                .addRequirements(testsWhoseNameContains("Two"));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertTrue(recorder.passed("SimpleTest.testSimpleTwo"));
    
public voidtestShouldRunSimpleTests()

        testSuiteBuilder.includePackages(packageFor(SimpleTest.class));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertTrue(recorder.passed("SimpleTest.testSimpleOne"));
        assertTrue(recorder.passed("SimpleTest.testSimpleTwo"));
        assertTrue(recorder.passed("AnotherSimpleTest.testAnotherOne"));
    
public voidtestShouldRunTestsInheritedFromSuperclass()

        testSuiteBuilder.includePackages(packageFor(SubclassTest.class));

        SuiteExecutionRecorder recorder = runSuite(testSuiteBuilder);

        assertEquals(2, getTestCaseNames(testSuiteBuilder.build()).size());

        assertTrue(recorder.passed("SubclassTest.testSubclass"));
        assertTrue(recorder.passed("SubclassTest.testSuperclass"));
        assertFalse(recorder.saw("SuperclassTest.testSuperclass"));
    
private com.android.internal.util.PredicatetestsWhoseNameContains(java.lang.String string)

        return new Predicate<TestMethod>() {
            public boolean apply(TestMethod testMethod) {
                return testMethod.getName().contains(string);
            }
        };