@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" ) ); } }
@Override public void execute(ExecutionRequest request) { EngineExecutionListener engineExecutionListener = request.getEngineExecutionListener(); TestDescriptor engineTestDescriptor = request.getRootTestDescriptor(); engineExecutionListener.executionStarted(engineTestDescriptor); RunnerExecutor runnerExecutor = new RunnerExecutor(engineExecutionListener); executeAllChildren(runnerExecutor, engineTestDescriptor); engineExecutionListener.executionFinished(engineTestDescriptor, successful()); }
TestExecutionResult getStoredResultOrSuccessful(TestDescriptor testDescriptor) { List<TestExecutionResult> testExecutionResults = executionResults.get(testDescriptor); if (testExecutionResults == null) { return successful(); } if (testExecutionResults.size() == 1) { return testExecutionResults.get(0); } // @formatter:off List<Throwable> failures = testExecutionResults .stream() .map(TestExecutionResult::getThrowable) .map(Optional::get) .collect(toList()); // @formatter:on return failed(new MultipleFailuresError("", failures)); } }
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(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { super.executionFinished(testIdentifier, testExecutionResult); testExecutionResult.getThrowable().ifPresent(exceptions::add); } }
/** * Convert the collected {@link Throwable Throwables} into a {@link TestExecutionResult}. * * @return {@linkplain TestExecutionResult#aborted aborted} if the collected * {@code Throwable} <em>aborted</em> execution; * {@linkplain TestExecutionResult#failed failed} if it <em>failed</em> * execution; and {@linkplain TestExecutionResult#successful successful} * otherwise */ TestExecutionResult toTestExecutionResult() { if (isEmpty()) { return successful(); } if (hasAbortedExecution(throwable)) { return aborted(throwable); } return failed(throwable); }
public void execute(RunnerTestDescriptor runnerTestDescriptor) { TestRun testRun = new TestRun(runnerTestDescriptor); JUnitCore core = new JUnitCore(); core.addListener(new RunListenerAdapter(testRun, engineExecutionListener)); try { core.run(runnerTestDescriptor.toRequest()); } catch (Throwable t) { BlacklistedExceptions.rethrowIfBlacklisted(t); reportUnexpectedFailure(testRun, runnerTestDescriptor, failed(t)); } }
@Override public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) { allTestsPassed = allTestsPassed && testExecutionResult.getStatus() == SUCCESSFUL; }
private static boolean isFailure(TestExecutionResult result) { Optional<Throwable> throwable = result.getThrowable(); return throwable.isPresent() && throwable.get() instanceof AssertionError; }
/** * Execute the supplied {@link Executable} and return a * {@link TestExecutionResult} based on the outcome. * * <p>If the {@code Executable} throws a <em>blacklisted</em> exception * — for example, an {@link OutOfMemoryError} — this method will * rethrow it. * * @param executable the test to be executed * @return {@linkplain TestExecutionResult#aborted aborted} if the * {@code Executable} throws a {@link TestAbortedException}; * {@linkplain TestExecutionResult#failed failed} if any other * {@link Throwable} is thrown; and {@linkplain TestExecutionResult#successful * successful} otherwise */ public TestExecutionResult executeSafely(Executable executable) { try { executable.execute(); return successful(); } catch (TestAbortedException e) { return aborted(e); } catch (Throwable t) { rethrowIfBlacklisted(t); return failed(t); } }
/** * 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; } }); } }
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(); }
private void printThrowable(String indent, TestExecutionResult result) { if (!result.getThrowable().isPresent()) { return; } Throwable throwable = result.getThrowable().get(); String message = throwable.getMessage(); if (StringUtils.isBlank(message)) { message = throwable.toString(); } printMessage(FAILED, indent, message); }
public static TestExecutionResult isSuccessful() { return eq(TestExecutionResult.successful()); }
private TestExecutionResult getResult(BenchmarkResult result, BenchmarkParams lastKnownBenchmark) { if (result != null) { return TestExecutionResult.successful(); } if (lastKnownBenchmark != null) { String output = StringUtils.collectionToDelimitedString(log, System.getProperty("line.separator")); return TestExecutionResult.failed(new JmhRunnerException(output)); } return TestExecutionResult.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); } }
private Failure toFailure(TestExecutionResult testExecutionResult, Description description) { return new Failure(description, testExecutionResult.getThrowable().orElse(null)); }
@Example void emptyEngine() { TestDescriptor engineDescriptor = forEngine(testEngine).build(); executeTests(engineDescriptor); InOrder events = Mockito.inOrder(eventRecorder); events.verify(eventRecorder).executionStarted(engineDescriptor); events.verify(eventRecorder).executionFinished(engineDescriptor, TestExecutionResult.successful()); }
public void execute(TestDescriptor testDescriptor, EngineExecutionListener listener) { JmhSupport support = new JmhSupport(); ChainedOptionsBuilder optionsBuilder = support.options(); List<AbstractBenchmarkDescriptor> methods = collectBenchmarkMethods(testDescriptor); List<AbstractBenchmarkDescriptor> includes = getIncludes(testDescriptor); if (!support.isEnabled()) { listener.executionSkipped(testDescriptor, "No benchmarks"); return; } List<String> includePatterns = evaluateBenchmarksToRun(includes, listener); if (!shouldRun(includePatterns)) { return; } includePatterns.forEach(optionsBuilder::include); CacheFunction cache = new CacheFunction(methods); Options options = optionsBuilder.build(); NotifyingOutputFormat notifyingOutputFormat = new NotifyingOutputFormat(listener, cache, support.createOutputFormat(options)); try { listener.executionStarted(testDescriptor); support.publishResults(notifyingOutputFormat, new Runner(options, notifyingOutputFormat).run()); listener.executionFinished(testDescriptor, TestExecutionResult.successful()); } catch (RunnerException e) { listener.executionFinished(testDescriptor, TestExecutionResult.failed(e)); } }