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)); } }
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)); } }
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(); }
/** * 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); }
/** * 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); } }
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)); } }