AI 143870: am: CL 143869 Change InstrumentationTestRunner so all tests in the application are run when no other arguments are supplied, instead of running only tests in the app's package.
Original author: brettchabot
Merged from: //branches/cupcake/...
Automated import of CL 143870
diff --git a/test-runner/android/test/ClassPathPackageInfoSource.java b/test-runner/android/test/ClassPathPackageInfoSource.java
index 12bc7f3..877075f 100644
--- a/test-runner/android/test/ClassPathPackageInfoSource.java
+++ b/test-runner/android/test/ClassPathPackageInfoSource.java
@@ -226,8 +226,11 @@
String className = apkClassNames.nextElement();
if (className.startsWith(packageName)) {
+ String subPackageName = packageName;
int lastPackageSeparator = className.lastIndexOf('.');
- String subPackageName = className.substring(0, lastPackageSeparator);
+ if (lastPackageSeparator > 0) {
+ subPackageName = className.substring(0, lastPackageSeparator);
+ }
if (subPackageName.length() > packageName.length()) {
subpackageNames.add(subPackageName);
} else if (isToplevelClass(className)) {
diff --git a/test-runner/android/test/InstrumentationTestRunner.java b/test-runner/android/test/InstrumentationTestRunner.java
index f038612..044f555 100644
--- a/test-runner/android/test/InstrumentationTestRunner.java
+++ b/test-runner/android/test/InstrumentationTestRunner.java
@@ -300,16 +300,17 @@
}
if (testClassesArg == null) {
- TestSuite testSuite = null;
if (mPackageOfTests != null) {
testSuiteBuilder.includePackages(mPackageOfTests);
} else {
- testSuite = getTestSuite();
- testSuiteBuilder.addTestSuite(testSuite);
- }
-
- if (testSuite == null) {
- testSuiteBuilder.includePackages(getTargetContext().getPackageName());
+ TestSuite testSuite = getTestSuite();
+ if (testSuite != null) {
+ testSuiteBuilder.addTestSuite(testSuite);
+ } else {
+ // no package or class bundle arguments were supplied, and no test suite
+ // provided so add all tests in application
+ testSuiteBuilder.includePackages("");
+ }
}
} else {
parseTestClasses(testClassesArg, testSuiteBuilder);