summaryrefslogtreecommitdiffstats
path: root/test-runner/tests
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-07-07 17:19:08 -0700
committerBrett Chabot <brettchabot@android.com>2010-07-07 17:33:22 -0700
commit31e7ce762ccbbb747fabb4581e42a0a2fe56e780 (patch)
treef9d5ff503a6ce35c29aa2da2f9bdc6359f6640dc /test-runner/tests
parentdacabf97c609a040ada857a7da6c560097448ae3 (diff)
downloadframeworks_base-31e7ce762ccbbb747fabb4581e42a0a2fe56e780.zip
frameworks_base-31e7ce762ccbbb747fabb4581e42a0a2fe56e780.tar.gz
frameworks_base-31e7ce762ccbbb747fabb4581e42a0a2fe56e780.tar.bz2
Improve InstrumentationTestRunner exception handling.
This commit fixes two somewhat related problems: - Attempting to run a method which does not exist caused a runtime exception which stopped the test run. Change this so the runner reports an individual test failure instead - A runtime exception during the test run would cause it to stop completely, with no information dumped to the logcat or stdout. Now exceptions are trapped and reported to stdout. Also added associated unit tests to test these two conditions. Related bug 2812262. Change-Id: I383f9b9bad99f14cb51071800fa9bdbf6a6a1119
Diffstat (limited to 'test-runner/tests')
-rw-r--r--test-runner/tests/src/android/test/InstrumentationTestRunnerTest.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/test-runner/tests/src/android/test/InstrumentationTestRunnerTest.java b/test-runner/tests/src/android/test/InstrumentationTestRunnerTest.java
index 6db72ad..d98b217 100644
--- a/test-runner/tests/src/android/test/InstrumentationTestRunnerTest.java
+++ b/test-runner/tests/src/android/test/InstrumentationTestRunnerTest.java
@@ -16,6 +16,7 @@
package android.test;
+import android.app.Instrumentation;
import android.content.Context;
import android.os.Bundle;
import android.test.mock.MockContext;
@@ -89,6 +90,42 @@ public class InstrumentationTestRunnerTest extends TestCase {
}
+ /**
+ * Test that runtime exceptions during runTest are handled gracefully
+ */
+ public void testUnhandledException() throws Exception {
+ StubAndroidTestRunner stubAndroidTestRunner = new StubAndroidTestRunner() {
+ @Override
+ public void runTest() {
+ throw new RuntimeException();
+ }
+ };
+ StubInstrumentationTestRunner instrumentationTestRunner = new StubInstrumentationTestRunner(
+ new StubContext("com.google.foo.tests"),
+ new StubContext(mTargetContextPackageName), stubAndroidTestRunner);
+ instrumentationTestRunner.onCreate(new Bundle());
+ instrumentationTestRunner.onStart();
+ assertTrue("Instrumentation did not finish", instrumentationTestRunner.isFinished());
+ // ensure a meaningful error message placed in results
+ String resultsData = instrumentationTestRunner.mResults.getString(
+ Instrumentation.REPORT_KEY_STREAMRESULT);
+ assertTrue("Instrumentation results is missing RuntimeException",
+ resultsData.contains("RuntimeException"));
+ }
+
+ /**
+ * Test that specifying a method which does not exist is handled gracefully
+ */
+ public void testBadMethodArgument() throws Exception {
+ String testClassName = PlaceHolderTest.class.getName();
+ String invalidMethodName = "testNoExist";
+ String classAndMethod = testClassName + "#" + invalidMethodName;
+ mInstrumentationTestRunner.onCreate(createBundle(
+ InstrumentationTestRunner.ARGUMENT_TEST_CLASS, classAndMethod));
+ assertTestRunnerCalledWithExpectedParameters(testClassName,
+ invalidMethodName);
+ }
+
public void testDelayParameter() throws Exception {
int delayMsec = 1000;
Bundle args = new Bundle();
@@ -170,6 +207,7 @@ public class InstrumentationTestRunnerTest extends TestCase {
private TestSuite mTestSuite;
private TestSuite mDefaultTestSuite;
private String mPackageNameForDefaultTests;
+ private Bundle mResults;
public StubInstrumentationTestRunner(Context context, Context targetContext,
AndroidTestRunner androidTestRunner) {
@@ -200,6 +238,7 @@ public class InstrumentationTestRunnerTest extends TestCase {
public void finish(int resultCode, Bundle results) {
mFinished = true;
+ mResults = results;
}
public boolean isStarted() {
@@ -221,6 +260,11 @@ public class InstrumentationTestRunnerTest extends TestCase {
public String getPackageNameForDefaultTests() {
return mPackageNameForDefaultTests;
}
+
+ @Override
+ void prepareLooper() {
+ // ignore
+ }
}
private static class StubContext extends MockContext {