diff --git a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestData.java b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestData.java index c16fa0e9..cd6c85a1 100644 --- a/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestData.java +++ b/java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestData.java @@ -80,7 +80,11 @@ public boolean isError() { return false; } - return result.getThrowable().map(thr -> thr instanceof AssertionError).orElse(false); + if (result.getStatus() == TestExecutionResult.Status.ABORTED) { + return true; + } + + return result.getThrowable().map(thr -> (!(thr instanceof AssertionError))).orElse(false); } public boolean isFailure() { @@ -90,11 +94,8 @@ public boolean isFailure() { || isSkipped()) { return false; } - if (result.getStatus() == TestExecutionResult.Status.ABORTED) { - return true; - } - return result.getThrowable().map(thr -> (!(thr instanceof AssertionError))).orElse(false); + return result.getThrowable().map(thr -> thr instanceof AssertionError).orElse(false); } public boolean isDisabled() { diff --git a/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java index 0547ca0c..83ff921e 100644 --- a/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java +++ b/java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java @@ -60,16 +60,16 @@ public class BazelJUnitOutputListenerTest { private TestDescriptor testDescriptor = new StubbedTestDescriptor(createId("descriptors")); private TestIdentifier identifier = TestIdentifier.from(testDescriptor); - /** This latch is used in TestAfterAllFails for testAfterAllFailuresAreReported */ - private static final AtomicBoolean causeFailure = new AtomicBoolean(false); + /** This latch is used in TestAfterAllErrors for testAfterAllFailuresAreReported */ + private static final AtomicBoolean causeError = new AtomicBoolean(false); - static final class TestAfterAllFails { + static final class TestAfterAllErrors { @SuppressFBWarnings(value = "THROWS_METHOD_THROWS_RUNTIMEEXCEPTION") @AfterAll static void afterAll() { - if (causeFailure.get()) { - throw new RuntimeException("I always fail."); + if (causeError.get()) { + throw new RuntimeException("I always error."); } } @@ -79,11 +79,11 @@ void test() {} @Test public void testAfterAllFailuresAreReported() throws IOException { - causeFailure.set(true); + causeError.set(true); // First let's do a sanity test that we have the expected failures for the @AfterAll EngineTestKit.engine("junit-jupiter") - .selectors(selectClass(TestAfterAllFails.class)) + .selectors(selectClass(TestAfterAllErrors.class)) .execute() .containerEvents() .assertStatistics(stats -> stats.skipped(0).started(2).succeeded(1).aborted(0).failed(1)); @@ -97,7 +97,7 @@ public void testAfterAllFailuresAreReported() throws IOException { Launcher launcher = LauncherFactory.create(config); LauncherDiscoveryRequestBuilder request = - LauncherDiscoveryRequestBuilder.request().selectors(selectClass(TestAfterAllFails.class)); + LauncherDiscoveryRequestBuilder.request().selectors(selectClass(TestAfterAllErrors.class)); launcher.discover(request.build()); @@ -106,7 +106,7 @@ public void testAfterAllFailuresAreReported() throws IOException { // now write an assertion to validate the XML file has an error String[] expectedStrings = { - "", "failures=\"1\"", + "", "errors=\"1\"", }; // Useful for debugging the expected output @@ -118,7 +118,7 @@ public void testAfterAllFailuresAreReported() throws IOException { "Expected to find " + expected + " in " + xmlFile); } - causeFailure.set(false); + causeError.set(false); } @Test @@ -338,14 +338,14 @@ void testSuiteError(@TempDir Path tempDir) assertEquals(1, testsuiteList.getLength()); Element testsuite = (Element) testsuiteList.item(0); assertEquals("4", testsuite.getAttribute("tests")); - assertEquals("4", testsuite.getAttribute("failures")); + assertEquals("4", testsuite.getAttribute("errors")); NodeList testcaseList = testsuite.getElementsByTagName("testcase"); assertEquals(4, testcaseList.getLength()); for (int i = 0; i < testcaseList.getLength(); i++) { Element testcase = (Element) testcaseList.item(i); - assertNotNull(getChild("failure", testcase)); + assertNotNull(getChild("error", testcase)); } } @@ -357,10 +357,10 @@ void throwablesWithNullMessageAreSerialized() { assertNotNull(root); assertEquals("testcase", root.getTagName()); - var failures = root.getElementsByTagName("failure"); - assertEquals(1, failures.getLength()); + var errors = root.getElementsByTagName("error"); + assertEquals(1, errors.getLength()); - var message = failures.item(0).getAttributes().getNamedItem("message"); + var message = errors.item(0).getAttributes().getNamedItem("message"); assertNotNull(message); assertEquals("null", message.getTextContent()); } @@ -387,10 +387,10 @@ void throwablesWithIllegalXmlCharactersInMessageAreSerialized() { assertNotNull(root); assertEquals("testcase", root.getTagName()); - var failures = root.getElementsByTagName("failure"); - assertEquals(1, failures.getLength()); + var errors = root.getElementsByTagName("error"); + assertEquals(1, errors.getLength()); - var message = failures.item(0).getAttributes().getNamedItem("message"); + var message = errors.item(0).getAttributes().getNamedItem("message"); assertNotNull(message); assertEquals( "legal: | | | [ -\uD7FF] | [\uE000-�]"