summaryrefslogtreecommitdiffstats
path: root/test-runner/tests
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-07-08 19:10:29 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-07-08 19:10:29 -0700
commitbbfe0b2264703c243e2e74631abd26fdf4459e36 (patch)
treee47eac80284822babe166ef4b099d9830010bbcc /test-runner/tests
parentd8a6271bb1da4ee2a8ae126b532f1b5f302decb8 (diff)
parent243f7f85ea9e57716590b9cf355e55d1f0236fce (diff)
downloadframeworks_base-bbfe0b2264703c243e2e74631abd26fdf4459e36.zip
frameworks_base-bbfe0b2264703c243e2e74631abd26fdf4459e36.tar.gz
frameworks_base-bbfe0b2264703c243e2e74631abd26fdf4459e36.tar.bz2
am 243f7f85: am f6120cf4: Merge "Improve InstrumentationTestRunner exception handling." into gingerbread
Merge commit '243f7f85ea9e57716590b9cf355e55d1f0236fce' * commit '243f7f85ea9e57716590b9cf355e55d1f0236fce': Improve InstrumentationTestRunner exception handling.
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 {