@Override public void executionFinished( TestIdentifier testIdentifier, TestExecutionResult testExecutionResult ) { if ( testExecutionResult.getStatus() == FAILED ) { resultsObserved++; String exceptionMessage = testExecutionResult.getThrowable().map( Throwable::getMessage ).orElse( EMPTY ); assertThat( exceptionMessage, containsString( "Fail to cleanup test directory for lockFileAndFailToDeleteDirectory" ) ); } }
/** * Invoke {@link TestWatcher#testSuccessful testSuccessful()}, * {@link TestWatcher#testAborted testAborted()}, or * {@link TestWatcher#testFailed testFailed()} on each * registered {@link TestWatcher} according to the status of the supplied * {@link TestExecutionResult}, in reverse registration order. * * @since 5.4 */ @Override public void nodeFinished(JupiterEngineExecutionContext context, TestDescriptor descriptor, TestExecutionResult result) { if (context != null) { ExtensionContext extensionContext = context.getExtensionContext(); TestExecutionResult.Status status = result.getStatus(); invokeTestWatchers(context, true, watcher -> { switch (status) { case SUCCESSFUL: watcher.testSuccessful(extensionContext); break; case ABORTED: watcher.testAborted(extensionContext, result.getThrowable().orElse(null)); break; case FAILED: watcher.testFailed(extensionContext, result.getThrowable().orElse(null)); break; } }); } }
static Color valueOf(TestExecutionResult result) { switch (result.getStatus()) { case SUCCESSFUL: return Color.SUCCESSFUL; case ABORTED: return Color.ABORTED; case FAILED: return Color.FAILED; default: return Color.NONE; } }
@Override public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) { allTestsPassed = allTestsPassed && testExecutionResult.getStatus() == SUCCESSFUL; }
void markFinished(TestIdentifier testIdentifier, TestExecutionResult result) { this.endInstants.put(testIdentifier, this.clock.instant()); if (result.getStatus() == ABORTED) { String reason = result.getThrowable().map(ExceptionUtils::readStackTrace).orElse(""); this.skippedTests.put(testIdentifier, reason); } else { this.finishedTests.put(testIdentifier, result); } }
Optional<TestExecutionResult> getResult(TestIdentifier testIdentifier) { if (this.finishedTests.containsKey(testIdentifier)) { return Optional.of(this.finishedTests.get(testIdentifier)); } Optional<TestIdentifier> parent = this.testPlan.getParent(testIdentifier); Optional<TestIdentifier> ancestor = findAncestor(parent, this.finishedTests::containsKey); if (ancestor.isPresent()) { TestExecutionResult result = this.finishedTests.get(ancestor.get()); if (result.getStatus() != SUCCESSFUL) { return Optional.of(result); } } return Optional.empty(); }
static TestCounts from(XmlReportData reportData, List<TestIdentifier> tests) { TestCounts counts = new TestCounts(tests.size()); for (TestIdentifier test : tests) { if (reportData.wasSkipped(test)) { counts.skipped++; } else { Optional<TestExecutionResult> result = reportData.getResult(test); if (result.isPresent() && result.get().getStatus() == FAILED) { if (isFailure(result.get())) { counts.failures++; } else { counts.errors++; } } } } return counts; }
private StackTraceWriter toStackTraceWriter( String realClassName, String realMethodName, TestExecutionResult testExecutionResult ) { switch ( testExecutionResult.getStatus() ) { case ABORTED: case FAILED: // Failed tests must have a StackTraceWriter, otherwise Surefire will fail Throwable exception = testExecutionResult.getThrowable().orElse( null ); return toStackTraceWriter( realClassName, realMethodName, exception ); default: return testExecutionResult.getThrowable() .map( t -> toStackTraceWriter( realClassName, realMethodName, t ) ) .orElse( null ); } }
private void writeSkippedOrErrorOrFailureElement(TestIdentifier testIdentifier, XMLStreamWriter writer) throws XMLStreamException { if (this.reportData.wasSkipped(testIdentifier)) { writeSkippedElement(this.reportData.getSkipReason(testIdentifier), writer); } else { Optional<TestExecutionResult> result = this.reportData.getResult(testIdentifier); if (result.isPresent() && result.get().getStatus() == FAILED) { writeErrorOrFailureElement(result.get(), writer); } } }
@Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { if (testIdentifier.isTest()) { switch (testExecutionResult.getStatus()) { case FAILED: this.getFailingTests().add( new Failure( this.toString.apply(testIdentifier), this.toClassName.apply(testIdentifier), testExecutionResult.getThrowable().get() ) ); break; default: break; } } }
@Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { if (testIdentifier.isTest()) { getMethodStats(testIdentifier).stopTime = clock.currentTimeMillis(); switch (testExecutionResult.getStatus()) { case SUCCESSFUL: break; case ABORTED: { break; } case FAILED: { eventsCollected.add(createEventFrom(testIdentifier, testExecutionResult)); break; } default: throw new PreconditionViolationException( "Unsupported execution status:" + testExecutionResult.getStatus()); } } }
@Override public boolean matches(TestExecutionResult result) { if (result.getStatus() != TestExecutionResult.Status.FAILED) return false; if (message == null) return true; return result.getThrowable().get().getMessage().equals(message); } }
private String colorCaption(TreeNode node) { String caption = node.caption(); if (node.result().isPresent()) { TestExecutionResult result = node.result().get(); Color resultColor = Color.valueOf(result); if (result.getStatus() != Status.SUCCESSFUL) { return color(resultColor, caption); } } if (node.reason().isPresent()) { return color(SKIPPED, caption); } Color color = node.identifier().map(Color::valueOf).orElse(Color.NONE); return color(color, caption); }
@Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { testExecutionResult.getThrowable().ifPresent(t -> printDetail(Color.FAILED, "caught", readStackTrace(t))); if (testIdentifier.isContainer()) { Long creationMillis = frames.pop(); printVerticals(theme.end()); printf(Color.CONTAINER, " %s", testIdentifier.getDisplayName()); printf(NONE, " finished after %d ms.%n", System.currentTimeMillis() - creationMillis); return; } printDetail(NONE, "duration", "%d ms%n", System.currentTimeMillis() - executionStartedMillis); String status = theme.status(testExecutionResult) + " " + testExecutionResult.getStatus(); printDetail(Color.valueOf(testExecutionResult), "status", "%s%n", status); }
@Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { if (testIdentifier.isTest()) { this.internalCoverage.getData().collect( this.internalCoverage.getExecutionData(), this.internalCoverage.getSessionInfos(), false ); final JUnit5Coverage jUnit5Coverage = new JUnit5Coverage(); jUnit5Coverage.collectData(this.internalCoverage.getExecutionData(), this.internalCoverage.getClassesDirectory()); this.internalCoverage.getCoverageResultsMap().put(this.toString.apply(testIdentifier), jUnit5Coverage); switch (testExecutionResult.getStatus()) { case FAILED: this.getFailingTests().add( new Failure( this.toString.apply(testIdentifier), this.toClassName.apply(testIdentifier), testExecutionResult.getThrowable().get() ) ); break; default: break; } } }
@Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { Description description = findJUnit4Description(testIdentifier); Status status = testExecutionResult.getStatus(); if (status == ABORTED) { this.notifier.fireTestAssumptionFailed(toFailure(testExecutionResult, description)); } else if (status == FAILED) { this.notifier.fireTestFailure(toFailure(testExecutionResult, description)); } if (description.isTest()) { this.notifier.fireTestFinished(description); } }
private void assertSingleFailedTest(ExecutionEventRecorder executionEventRecorder, Class<? extends Throwable> clazz, String message) { assertEquals(1, executionEventRecorder.getTestStartedCount()); assertEquals(1, executionEventRecorder.getTestFailedCount()); assertEquals(0, executionEventRecorder.getTestSuccessfulCount()); ExecutionEvent executionEvent = executionEventRecorder.getFailedTestFinishedEvents().get(0); Optional<TestExecutionResult> result = executionEvent.getPayload(TestExecutionResult.class); assertThat(result).isPresent(); assertThat(result.get().getStatus()).isEqualTo(FAILED); Optional<Throwable> throwable = result.get().getThrowable(); assertThat(throwable).containsInstanceOf(clazz); assertThat(throwable.get()).hasMessageContaining(message); } }
switch ( testExecutionResult.getStatus() )