aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-04-19 13:32:08 -0700
committerBrett Chabot <brettchabot@android.com>2010-04-19 18:14:53 -0700
commit88f8a8b41ed66b09aae26e50a3cdf5636a774a06 (patch)
tree68bcf2d6f9d750280fa24da7ba0c36e75dd1fdcd
parentdd47b5fd5a36ca572125a50ea50fb217b865cad7 (diff)
downloadsdk-88f8a8b41ed66b09aae26e50a3cdf5636a774a06.zip
sdk-88f8a8b41ed66b09aae26e50a3cdf5636a774a06.tar.gz
sdk-88f8a8b41ed66b09aae26e50a3cdf5636a774a06.tar.bz2
Make test runner parser detect runs with no tests.
Add logic to differeniate between an incomplete test run, and a test run which completed successfully but has no tests. Fixes bug http://b.android.com/7830 Change-Id: I54068de73e068faae6e34779b91665f6d1dc1a47
-rwxr-xr-xddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java12
-rw-r--r--ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java47
2 files changed, 46 insertions, 13 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
index 2bc5710..ff49c44 100755
--- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
+++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/InstrumentationResultParser.java
@@ -138,6 +138,9 @@ public class InstrumentationResultParser extends MultiLineReceiver {
/** True if start of test has already been reported to listener. */
private boolean mTestStartReported = false;
+ /** True if the completion of the test run has been detected. */
+ private boolean mTestRunFinished = false;
+
/** True if test run failure has already been reported to listener. */
private boolean mTestRunFailReported = false;
@@ -226,6 +229,8 @@ public class InstrumentationResultParser extends MultiLineReceiver {
line.startsWith(Prefixes.CODE)) {
// Previous status key-value has been collected. Store it.
submitCurrentKeyValue();
+ // these codes signal the end of the instrumentation run
+ mTestRunFinished = true;
// just ignore the remaining data on this line
} else if (line.startsWith(Prefixes.TIME_REPORT)) {
parseTime(line, Prefixes.TIME_REPORT.length());
@@ -470,7 +475,7 @@ public class InstrumentationResultParser extends MultiLineReceiver {
@Override
public void done() {
super.done();
- if (!mTestRunFailReported && !mTestStartReported) {
+ if (!mTestRunFailReported && !mTestStartReported && !mTestRunFinished) {
// no results
handleTestRunFailed(NO_TEST_RESULTS_MSG);
} else if (!mTestRunFailReported && mNumTestsExpected > mNumTestsRun) {
@@ -480,6 +485,11 @@ public class InstrumentationResultParser extends MultiLineReceiver {
handleTestRunFailed(message);
} else {
for (ITestRunListener listener : mTestListeners) {
+ if (!mTestStartReported) {
+ // test run wasn't started, but it finished successfully. Must be a run with
+ // no tests
+ listener.testRunStarted(0);
+ }
listener.testRunEnded(mTestTime);
}
}
diff --git a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
index ee227f0..ed3a420 100644
--- a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
+++ b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/InstrumentationResultParserTest.java
@@ -170,17 +170,12 @@ public class InstrumentationResultParserTest extends TestCase {
*/
public void testRunAmFailed() {
StringBuilder output = new StringBuilder();
- output.append("usage: am [subcommand] [options]");
- addLineBreak(output);
- output.append("start an Activity: am start [-D] [-W] <INTENT>");
- addLineBreak(output);
- output.append("-D: enable debugging");
- addLineBreak(output);
- output.append("-W: wait for launch to complete");
- addLineBreak(output);
- output.append("start a Service: am startservice <INTENT>");
- addLineBreak(output);
- output.append("Error: Bad component name: wfsdafddfasasdf");
+ addLine(output, "usage: am [subcommand] [options]");
+ addLine(output, "start an Activity: am start [-D] [-W] <INTENT>");
+ addLine(output, "-D: enable debugging");
+ addLine(output, "-W: wait for launch to complete");
+ addLine(output, "start a Service: am startservice <INTENT>");
+ addLine(output, "Error: Bad component name: wfsdafddfasasdf");
injectTestString(output.toString());
@@ -189,6 +184,27 @@ public class InstrumentationResultParserTest extends TestCase {
}
/**
+ * Test parsing of a test run that has no tests.
+ * <p/>
+ * Expect run to be reported as success.
+ */
+ public void testRunNoResults() {
+ StringBuilder output = new StringBuilder();
+ addLine(output, "INSTRUMENTATION_RESULT: stream=");
+ addLine(output, "Test results for InstrumentationTestRunner=");
+ addLine(output, "Time: 0.001");
+ addLine(output, "OK (0 tests)");
+ addLine(output, "INSTRUMENTATION_CODE: -1");
+
+ injectTestString(output.toString());
+
+ assertEquals(0, mTestResult.mTestCount);
+ assertNull(mTestResult.mRunFailedMessage);
+ assertEquals(1, mTestResult.mTestTime);
+ assertFalse(mTestResult.mStopped);
+ }
+
+ /**
* Builds a common test result using TEST_NAME and TEST_CLASS.
*/
private StringBuilder buildCommonResult() {
@@ -218,7 +234,6 @@ public class InstrumentationResultParserTest extends TestCase {
*/
private void addStackTrace(StringBuilder output) {
addStatusKey(output, "stack", STACK_TRACE);
-
}
/**
@@ -234,6 +249,14 @@ public class InstrumentationResultParserTest extends TestCase {
}
/**
+ * Append a line to output.
+ */
+ private void addLine(StringBuilder outputBuilder, String lineContent) {
+ outputBuilder.append(lineContent);
+ addLineBreak(outputBuilder);
+ }
+
+ /**
* Append line break characters to output
*/
private void addLineBreak(StringBuilder outputBuilder) {