Skip to content

Commit

Permalink
Surefire: Report tests with non-AssertionError causes as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp authored and Andrei94 committed Jun 23, 2018
1 parent e517f46 commit 974a807
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions documentation/src/docs/asciidoc/release-notes-5.0.0-RC3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ on GitHub.
===== Bug Fixes

* Source JARs no longer contain every source file twice.
* The Surefire provider now reports failed tests with a cause that is not instance of
`AssertionError` as errors instead of failures for compatibility reasons.

===== New Features and Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,23 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
runListener.testAssumptionFailure(createReportEntry(testIdentifier, testExecutionResult.getThrowable()));
}
else if (testExecutionResult.getStatus() == FAILED) {
runListener.testFailed(createReportEntry(testIdentifier, testExecutionResult.getThrowable()));
reportFailedTest(testIdentifier, testExecutionResult.getThrowable());
}
else if (testIdentifier.isTest()) {
runListener.testSucceeded(createReportEntry(testIdentifier, Optional.empty()));
}
}

private void reportFailedTest(TestIdentifier testIdentifier, Optional<Throwable> throwable) {
SimpleReportEntry reportEntry = createReportEntry(testIdentifier, throwable);
if (throwable.filter(AssertionError.class::isInstance).isPresent()) {
runListener.testFailed(reportEntry);
}
else {
runListener.testError(reportEntry);
}
}

private SimpleReportEntry createReportEntry(TestIdentifier testIdentifier, Optional<Throwable> throwable) {
Optional<String> className = getClassName(testIdentifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,25 @@ void notifiedWhenClassExecutionAborted() throws Exception {
}

@Test
void notifiedWhenMethodExecutionFailed() throws Exception {
adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.failed(new RuntimeException()));
void notifiedWhenMethodExecutionFailedWithAnAssertionError() throws Exception {
adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.failed(new AssertionError()));
verify(listener).testFailed(any());
}

@Test
void notifiedWhenMethodExecutionFailedWithANonAssertionError() throws Exception {
adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.failed(new RuntimeException()));
verify(listener).testError(any());
}

@Test
void notifiedWithCorrectNamesWhenClassExecutionFailed() throws Exception {
ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
adapter.testPlanExecutionStarted(testPlan);

adapter.executionFinished(identifiersAsParentOnTestPlan(testPlan, newEngineDescriptor(), newClassDescriptor()),
TestExecutionResult.failed(new RuntimeException()));
TestExecutionResult.failed(new AssertionError()));
verify(listener).testFailed(entryCaptor.capture());

ReportEntry entry = entryCaptor.getValue();
Expand Down

0 comments on commit 974a807

Please sign in to comment.