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


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
public static final Comparator
public static final Comparator
protected String
private 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.

packageNames Names of packages to add.
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");
            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()

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

        return firstIncludedPackage;

        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()

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.

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

        for (String packageName : packageNames) {
        return this;
private java.util.Listselect(java.util.Collection items, predicate)

        ArrayList<T> selectedItems = new ArrayList<T>();
        for (T item : items) {
            if (predicate.apply(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());