Skip to content

Commit

Permalink
[junit-platform] Report total failure count, not just test failures
Browse files Browse the repository at this point in the history
This is necessary as Jupiter reports container failures separately
from the children if the container fails before the children are
executed.

Fixes bndtools#4175.

Signed-off-by: Fr Jeremy Krieg <[email protected]>
  • Loading branch information
kriegfrj committed Jun 21, 2020
1 parent 450c34d commit 2a9b5ab
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ long test(LauncherDiscoveryRequest testRequest) {
}

return summary.getSummary()
.getTestsFailedCount();
.getTotalFailureCount();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aQute.tester.testclasses.junit.platform;

import org.junit.BeforeClass;
import org.junit.Test;

public class JUnit4ContainerError {

@BeforeClass
void beforeAll() {
throw new IllegalStateException();
}

@Test
void myTest() {
throw new AssertionError();
}

@Test
void my2ndTest() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aQute.tester.testclasses.junit.platform;

import org.junit.BeforeClass;
import org.junit.Test;

public class JUnit4ContainerFailure {

@BeforeClass
void beforeAll() {
throw new AssertionError();
}

@Test
void myTest() {
throw new AssertionError();
}

@Test
void my2ndTest() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aQute.tester.testclasses.junit.platform;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class JUnit5ContainerError {

@BeforeAll
void beforeAll() {
throw new IllegalStateException();
}

@Test
void myTest() {
throw new AssertionError();
}

@Test
void my2ndTest() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aQute.tester.testclasses.junit.platform;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class JUnit5ContainerFailure {

@BeforeAll
void beforeAll() {
throw new AssertionError();
}

@Test
void myTest() {
throw new AssertionError();
}

@Test
void my2ndTest() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import aQute.tester.testclasses.junit.platform.JUnit4ComparisonTest;
import aQute.tester.testclasses.junit.platform.JUnit4Skipper;
import aQute.tester.testclasses.junit.platform.JUnit5AbortTest;
import aQute.tester.testclasses.junit.platform.JUnit5ContainerError;
import aQute.tester.testclasses.junit.platform.JUnit5ContainerFailure;
import aQute.tester.testclasses.junit.platform.JUnit5ContainerSkipped;
import aQute.tester.testclasses.junit.platform.JUnit5ContainerSkippedWithCustomDisplayName;
import aQute.tester.testclasses.junit.platform.JUnit5DisplayNameTest;
Expand Down Expand Up @@ -585,4 +587,11 @@ public void xmlReporter_generatesCompleteXmlFile() throws Exception {
.nodesByXPath(testCaseFailure(With2Failures.class, "test3", CustomAssertionError.class))
.hasSize(1);
}

// Unlike JUnit 4, Jupiter skips the tests when the parent container
// fails and does not report the children as test failures.
@Test
public void exitCode_countsJupiterContainerErrorsAndFailures() {
runTests(2, JUnit5ContainerFailure.class, JUnit5ContainerError.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import aQute.tester.testclasses.JUnit4Test;
import aQute.tester.testclasses.With1Error1Failure;
import aQute.tester.testclasses.With2Failures;
import aQute.tester.testclasses.junit.platform.JUnit4ContainerError;
import aQute.tester.testclasses.junit.platform.JUnit4ContainerFailure;

// Because we're not in the same project as aQute.junit.TesterConstants and its bundle-private.
public abstract class AbstractActivatorTest extends SoftAssertions {
Expand Down Expand Up @@ -516,6 +518,11 @@ public void exitCode_countsErrorsAndFailures() {
assertThat(exitCode.exitCode).isEqualTo(4);
}

@Test
public void exitCode_countsContainerErrorsAndFailures() {
runTests(8, JUnit4ContainerFailure.class, JUnit4ContainerError.class);
}

protected TestRunData runTestsEclipse(Callback postCreateCallback, Class<?>... tests) {
return runTestsEclipse(postCreateCallback, new Class<?>[][] {
tests
Expand Down

0 comments on commit 2a9b5ab

Please sign in to comment.