Methods Summary |
---|
public final android.test.suitebuilder.TestSuiteBuilder | addRequirements(com.android.internal.util.Predicate predicates)Exclude tests that fail to satisfy all of the given predicates. If you call this method, you
probably also want to call {@link #named(String)} to override the default suite name.
ArrayList<Predicate<TestMethod>> list = new ArrayList<Predicate<TestMethod>>();
Collections.addAll(list, predicates);
return addRequirements(list);
|
public android.test.suitebuilder.TestSuiteBuilder | addRequirements(java.util.List predicates)Exclude tests that fail to satisfy all of the given predicates.
this.predicates.addAll(predicates);
return this;
|
private void | addSuiteIfNecessary(java.lang.String parentClassname)
if (!parentClassname.equals(currentClassname)) {
currentClassname = parentClassname;
suiteForCurrentClass = new TestSuite(parentClassname);
rootSuite.addTest(suiteForCurrentClass);
}
|
private void | addTest(TestMethod testMethod)
addSuiteIfNecessary(testMethod.getEnclosingClassname());
suiteForCurrentClass.addTest(testMethod.createTest());
|
private void | addTest(junit.framework.Test test)
addSuiteIfNecessary(test.getClass().getName());
suiteForCurrentClass.addTest(test);
|
public android.test.suitebuilder.TestSuiteBuilder | addTestClassByName(java.lang.String testClassName, java.lang.String testMethodName, android.content.Context context)
AndroidTestRunner atr = new AndroidTestRunner();
atr.setContext(context);
atr.setTestClassName(testClassName, testMethodName);
this.testCases.addAll(atr.getTestCases());
return this;
|
public android.test.suitebuilder.TestSuiteBuilder | addTestSuite(junit.framework.TestSuite testSuite)
for (TestCase testCase : (List<TestCase>) TestCaseUtil.getTests(testSuite, true)) {
this.testCases.add(testCase);
}
return this;
|
public final junit.framework.TestSuite | build()Call this method once you've configured your builder as desired.
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;
|
public android.test.suitebuilder.TestSuiteBuilder | excludePackages(java.lang.String packageNames)Exclude all tests in the given packages and all sub-packages, unless otherwise specified.
testGrouping.removePackagesRecursive(packageNames);
return this;
|
protected java.lang.String | getSuiteName()Subclasses use this method to determine the name of the suite.
return suiteName;
|
protected TestGrouping | getTestGrouping()
return testGrouping;
|
public final android.test.suitebuilder.TestSuiteBuilder | includeAllPackagesUnderHere()Include all junit tests that satisfy the requirements in the calling class' package and all
sub-packages.
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
String callingClassName = null;
String thisClassName = TestSuiteBuilder.class.getName();
// We want to get the package of this method's calling class. This method's calling class
// should be one level below this class in the stack trace.
for (int i = 0; i < stackTraceElements.length; i++) {
StackTraceElement element = stackTraceElements[i];
if (thisClassName.equals(element.getClassName())
&& "includeAllPackagesUnderHere".equals(element.getMethodName())) {
// We've found this class in the call stack. The calling class must be the
// next class in the stack.
callingClassName = stackTraceElements[i + 1].getClassName();
break;
}
}
String packageName = parsePackageNameFromClassName(callingClassName);
return includePackages(packageName);
|
public android.test.suitebuilder.TestSuiteBuilder | includePackages(java.lang.String packageNames)Include all tests that satisfy the requirements in the given packages and all sub-packages,
unless otherwise specified.
testGrouping.addPackagesRecursive(packageNames);
return this;
|
public android.test.suitebuilder.TestSuiteBuilder | named(java.lang.String newSuiteName)Override the default name for the suite being built. This should generally be called if you
call {@link #addRequirements(com.android.internal.util.Predicate[])} to make it clear which
tests will be included. The name you specify is automatically prefixed with the package
containing the tests to be run. If more than one package is specified, the first is used.
suiteName = newSuiteName;
return this;
|
private static java.lang.String | parsePackageNameFromClassName(java.lang.String className)
return className.substring(0, className.lastIndexOf('."));
|
private boolean | satisfiesAllPredicates(TestMethod test)
for (Predicate<TestMethod> predicate : predicates) {
if (!predicate.apply(test)) {
return false;
}
}
return true;
|