summaryrefslogtreecommitdiffstats
path: root/test-runner
diff options
context:
space:
mode:
authorBrian Muramatsu <btmura@google.com>2012-04-03 11:46:56 -0700
committerBrian Muramatsu <btmura@google.com>2012-04-03 11:46:56 -0700
commit87571b75e6560d33b8de7ca04801612a20a04d98 (patch)
tree34168684a354f369557dc324f440269aa220f1b9 /test-runner
parent5eeee5e0bbf5aba0097a510b3e9dbb286b2b30cd (diff)
downloadframeworks_base-87571b75e6560d33b8de7ca04801612a20a04d98.zip
frameworks_base-87571b75e6560d33b8de7ca04801612a20a04d98.tar.gz
frameworks_base-87571b75e6560d33b8de7ca04801612a20a04d98.tar.bz2
Try Alternate Constructor for Single Method Tests
Some tests do not have a no argument constructor. If they don't have one, then try a constructor with a String argument. A lot of CTS tests from open source projects have different practices and may not have a no arg constructor. Change-Id: I87c490c22347a2f4b03c3125308be0d2259f9208
Diffstat (limited to 'test-runner')
-rw-r--r--test-runner/src/android/test/AndroidTestRunner.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/test-runner/src/android/test/AndroidTestRunner.java b/test-runner/src/android/test/AndroidTestRunner.java
index fc9832c..30876d0 100644
--- a/test-runner/src/android/test/AndroidTestRunner.java
+++ b/test-runner/src/android/test/AndroidTestRunner.java
@@ -28,6 +28,7 @@ import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.runner.BaseTestRunner;
+import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@@ -91,15 +92,35 @@ public class AndroidTestRunner extends BaseTestRunner {
private TestCase buildSingleTestMethod(Class testClass, String testMethodName) {
try {
- TestCase testCase = (TestCase) testClass.newInstance();
+ Constructor c = testClass.getConstructor();
+ return newSingleTestMethod(testClass, testMethodName, c);
+ } catch (NoSuchMethodException e) {
+ }
+
+ try {
+ Constructor c = testClass.getConstructor(String.class);
+ return newSingleTestMethod(testClass, testMethodName, c, testMethodName);
+ } catch (NoSuchMethodException e) {
+ }
+
+ return null;
+ }
+
+ private TestCase newSingleTestMethod(Class testClass, String testMethodName,
+ Constructor constructor, Object... args) {
+ try {
+ TestCase testCase = (TestCase) constructor.newInstance(args);
testCase.setName(testMethodName);
return testCase;
} catch (IllegalAccessException e) {
runFailed("Could not access test class. Class: " + testClass.getName());
} catch (InstantiationException e) {
runFailed("Could not instantiate test class. Class: " + testClass.getName());
+ } catch (IllegalArgumentException e) {
+ runFailed("Illegal argument passed to constructor. Class: " + testClass.getName());
+ } catch (InvocationTargetException e) {
+ runFailed("Constructor thew an exception. Class: " + testClass.getName());
}
-
return null;
}