diff options
author | 2017-09-22 11:48:31 +0200 | |
---|---|---|
committer | 2017-09-22 12:16:11 +0200 | |
commit | 7b091c1397a82258e26ab5336df6c8dae1d97384 (patch) | |
tree | 65bda619800ea078c6822cc232777b69537fd134 /src/java_tools/junitrunner/java | |
parent | 9faf8b7458c496a8d2b2a0040dcc2bb285b52e1b (diff) |
Add a global failure when a test is interrupted/cancelled.
When a timeout occurred, the current test case is interrupted and the others are cancelled. This was not reflected in any way and all tests were reported as success, even if there was a timeout and the tests were cancelled/interrupted.
Also add a status xml attribute to mark if the test was completed, cancelled or interrupted.
Fixes #3763
RELNOTES: None.
PiperOrigin-RevId: 169665622
Diffstat (limited to 'src/java_tools/junitrunner/java')
2 files changed, 6 insertions, 1 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java index 8ee4ba3a64..11870ae3f1 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/AntXmlResultWriter.java @@ -49,6 +49,7 @@ public final class AntXmlResultWriter implements XmlResultWriter { private static final String JUNIT_ATTR_PROPERTY_VALUE = "value"; private static final String JUNIT_ELEMENT_TESTCASE = "testcase"; private static final String JUNIT_ELEMENT_FAILURE = "failure"; + private static final String JUNIT_ELEMENT_STATUS = "status"; private static final String JUNIT_ATTR_FAILURE_MESSAGE = "message"; private static final String JUNIT_ATTR_FAILURE_TYPE = "type"; private static final String JUNIT_ATTR_TESTCASE_NAME = "name"; @@ -162,6 +163,7 @@ public final class AntXmlResultWriter implements XmlResultWriter { writer.writeAttribute(JUNIT_ATTR_TESTCASE_CLASSNAME, result.getClassName()); writer.writeAttribute(JUNIT_ATTR_TESTCASE_TIME, getFormattedRunTime( result.getRunTimeInterval())); + writer.writeAttribute(JUNIT_ELEMENT_STATUS, result.getStatus().toString()); for (Throwable failure : parentFailures) { writeThrowableToXmlWriter(writer, failure); diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java index cdaaf953fe..866252343e 100644 --- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java +++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java @@ -81,9 +81,12 @@ class TestCaseNode extends TestNode @Override public void testInterrupted(long now) { if (compareAndSetState(State.STARTED, State.INTERRUPTED, now)) { + globalFailures.add(new Exception("Test interrupted")); return; } - compareAndSetState(INITIAL_STATES, State.CANCELLED, now); + if (compareAndSetState(INITIAL_STATES, State.CANCELLED, now)) { + globalFailures.add(new Exception("Test cancelled")); + } } @Override |