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

TestGrouping

public class TestGrouping extends Object
Represents a collection of test classes present on the classpath. You can add individual classes or entire packages. By default sub-packages are included recursively, but methods are provided to allow for arbitrary inclusion or exclusion of sub-packages. Typically a {@link TestGrouping} will have only one root package, but this is not a requirement. {@hide} Not needed for 1.0 SDK.

Fields Summary
SortedSet
testCaseClasses
public static final Comparator
SORT_BY_SIMPLE_NAME
public static final Comparator
SORT_BY_FULLY_QUALIFIED_NAME
protected String
firstIncludedPackage
private ClassLoader
classLoader
Constructors Summary
public TestGrouping(Comparator comparator)


         
        testCaseClasses = new TreeSet<Class<? extends TestCase>>(comparator);
    
Methods Summary
public android.test.suitebuilder.TestGroupingaddPackagesRecursive(java.lang.String packageNames)
Include all tests in the given packages and all their sub-packages, unless otherwise specified. Each of the given packages must contain at least one test class, either directly or in a sub-package.

param
packageNames Names of packages to add.
return
The {@link TestGrouping} for method chaining.

        for (String packageName : packageNames) {
            List<Class<? extends TestCase>> addedClasses = testCaseClassesInPackage(packageName);
            if (addedClasses.isEmpty()) {
                Log.w("TestGrouping", "Invalid Package: '" + packageName
                        + "' could not be found or has no tests");
            }
            testCaseClasses.addAll(addedClasses);
            if (firstIncludedPackage == null) {
                firstIncludedPackage = packageName;
            }
        }
        return this;
    
public booleanequals(java.lang.Object o)

        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TestGrouping other = (TestGrouping) o;
        if (!this.testCaseClasses.equals(other.testCaseClasses)) {
            return false;
        }
        return this.testCaseClasses.comparator().equals(other.testCaseClasses.comparator());
    
public java.lang.StringgetFirstIncludedPackage()

return
The first package name passed to {@link #addPackagesRecursive(String[])}, or null if that method was never called.

        return firstIncludedPackage;
    
java.util.SortedSetgetTestCaseClasses()

        return testCaseClasses;
    
protected java.util.ListgetTestMethods(java.lang.Class testCaseClass)

        List<Method> methods = Arrays.asList(testCaseClass.getMethods());
        return select(methods, new TestMethodPredicate());
    
public java.util.ListgetTests()

return
A list of all tests in the package, including small, medium, large, flaky, and suppressed tests. Includes sub-packages recursively.

        List<TestMethod> testMethods = new ArrayList<TestMethod>();
        for (Class<? extends TestCase> testCase : testCaseClasses) {
            for (Method testMethod : getTestMethods(testCase)) {
                testMethods.add(new TestMethod(testMethod, testCase));
            }
        }
        return testMethods;
    
public inthashCode()

        return testCaseClasses.hashCode();
    
public android.test.suitebuilder.TestGroupingremovePackagesRecursive(java.lang.String packageNames)
Exclude all tests in the given packages and all their sub-packages, unless otherwise specified.

param
packageNames Names of packages to remove.
return
The {@link TestGrouping} for method chaining.

        for (String packageName : packageNames) {
            testCaseClasses.removeAll(testCaseClassesInPackage(packageName));
        }
        return this;
    
private java.util.Listselect(java.util.Collection items, com.android.internal.util.Predicate predicate)

        ArrayList<T> selectedItems = new ArrayList<T>();
        for (T item : items) {
            if (predicate.apply(item)) {
                selectedItems.add(item);
            }
        }
        return selectedItems;
    
private java.util.ListselectTestClasses(java.util.Set allClasses)

        List<Class<? extends TestCase>> testClasses = new ArrayList<Class<? extends TestCase>>();
        for (Class<?> testClass : select(allClasses,
                new TestCasePredicate())) {
            testClasses.add((Class<? extends TestCase>) testClass);
        }
        return testClasses;
    
public voidsetClassLoader(java.lang.ClassLoader classLoader)

        this.classLoader = classLoader;
    
private java.util.ListtestCaseClassesInPackage(java.lang.String packageName)

        ClassPathPackageInfoSource source = PackageInfoSources.forClassPath(classLoader);
        ClassPathPackageInfo packageInfo = source.getPackageInfo(packageName);

        return selectTestClasses(packageInfo.getTopLevelClassesRecursive());