summaryrefslogtreecommitdiffstats
path: root/test-runner
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-19 10:57:31 -0800
commit3001a035439d8134a7d70d796376d1dfbff3cdcd (patch)
tree343ccdba15a594ff6e50c874a145232753315a30 /test-runner
parentda996f390e17e16f2dfa60e972e7ebc4f868f37e (diff)
downloadframeworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.zip
frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.gz
frameworks_base-3001a035439d8134a7d70d796376d1dfbff3cdcd.tar.bz2
auto import from //branches/cupcake/...@132276
Diffstat (limited to 'test-runner')
-rw-r--r--test-runner/android/test/ServiceTestCase.java4
-rw-r--r--test-runner/android/test/TestCaseUtil.java38
2 files changed, 35 insertions, 7 deletions
diff --git a/test-runner/android/test/ServiceTestCase.java b/test-runner/android/test/ServiceTestCase.java
index c53bf7d..fcb9d55 100644
--- a/test-runner/android/test/ServiceTestCase.java
+++ b/test-runner/android/test/ServiceTestCase.java
@@ -48,7 +48,7 @@ import java.util.Random;
* the test case will call onCreate(), and then call the corresponding entry point in your service.
* It will record any parameters or other support values necessary to support the lifecycle.</li>
* <li>After your test completes, the test case {@link #tearDown} function is
- * automatically called, and it will stop & destroy your service with the appropriate
+ * automatically called, and it will stop and destroy your service with the appropriate
* calls (depending on how your test invoked the service.)</li>
* </ul>
*
@@ -172,7 +172,7 @@ public abstract class ServiceTestCase<T extends Service> extends AndroidTestCase
* Return the communication channel to the service. May return null if
* clients can not bind to the service. The returned
* {@link android.os.IBinder} is usually for a complex interface
- * that has been <a href="{@docRoot}reference/aidl.html">described using
+ * that has been <a href="{@docRoot}guide/developing/tools/aidl.html">described using
* aidl</a>.
*
* Note: In order to test with this interface, your service must implement a getService()
diff --git a/test-runner/android/test/TestCaseUtil.java b/test-runner/android/test/TestCaseUtil.java
index 4109d9c..3ba9711 100644
--- a/test-runner/android/test/TestCaseUtil.java
+++ b/test-runner/android/test/TestCaseUtil.java
@@ -17,6 +17,7 @@
package android.test;
import com.google.android.collect.Lists;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -26,7 +27,9 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @hide - This is part of a framework that is under development and should not be used for
@@ -48,10 +51,25 @@ public class TestCaseUtil {
}
public static List<? extends Test> getTests(Test test, boolean flatten) {
+ return getTests(test, flatten, new HashSet<Class<?>>());
+ }
+
+ private static List<? extends Test> getTests(Test test, boolean flatten,
+ Set<Class<?>> seen) {
List<Test> testCases = Lists.newArrayList();
if (test != null) {
- Test workingTest = invokeSuiteMethodIfPossible(test.getClass());
+ Test workingTest = null;
+ /*
+ * If we want to run a single TestCase method only, we must not
+ * invoke the suite() method, because we will run all test methods
+ * of the class then.
+ */
+ if (test instanceof TestCase &&
+ ((TestCase)test).getName() == null) {
+ workingTest = invokeSuiteMethodIfPossible(test.getClass(),
+ seen);
+ }
if (workingTest == null) {
workingTest = test;
}
@@ -62,7 +80,7 @@ public class TestCaseUtil {
while (enumeration.hasMoreElements()) {
Test childTest = (Test) enumeration.nextElement();
if (flatten) {
- testCases.addAll(getTests(childTest, flatten));
+ testCases.addAll(getTests(childTest, flatten, seen));
} else {
testCases.add(childTest);
}
@@ -74,11 +92,20 @@ public class TestCaseUtil {
return testCases;
}
- private static Test invokeSuiteMethodIfPossible(Class testClass) {
+ private static Test invokeSuiteMethodIfPossible(Class testClass,
+ Set<Class<?>> seen) {
try {
Method suiteMethod = testClass.getMethod(
BaseTestRunner.SUITE_METHODNAME, new Class[0]);
- if (Modifier.isStatic(suiteMethod.getModifiers())) {
+ /*
+ * Additional check necessary: If a TestCase contains a suite()
+ * method that returns a TestSuite including the TestCase itself,
+ * we need to stop the recursion. We use a set of classes to
+ * remember which classes' suite() methods were already invoked.
+ */
+ if (Modifier.isStatic(suiteMethod.getModifiers())
+ && !seen.contains(testClass)) {
+ seen.add(testClass);
try {
return (Test) suiteMethod.invoke(null, (Object[]) null);
} catch (InvocationTargetException e) {
@@ -128,7 +155,8 @@ public class TestCaseUtil {
public static TestSuite createTestSuite(Class<? extends Test> testClass)
throws InstantiationException, IllegalAccessException {
- Test test = invokeSuiteMethodIfPossible(testClass);
+ Test test = invokeSuiteMethodIfPossible(testClass,
+ new HashSet<Class<?>>());
if (test == null) {
return new TestSuite(testClass);