use of org.junit.platform.launcher.Launcher in project spring-framework by spring-projects.
the class FailingBeforeAndAfterMethodsSpringExtensionTestCase method runTestAndAssertCounters.
private void runTestAndAssertCounters(Class<?> testClass) {
Launcher launcher = LauncherFactory.create();
ExceptionTrackingListener listener = new ExceptionTrackingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request().selectors(selectClass(testClass)).build());
TestExecutionSummary summary = listener.getSummary();
String name = testClass.getSimpleName();
int expectedStartedCount = getExpectedStartedCount(testClass);
int expectedSucceededCount = getExpectedSucceededCount(testClass);
int expectedFailedCount = getExpectedFailedCount(testClass);
// @formatter:off
assertAll(() -> assertEquals(1, summary.getTestsFoundCount(), () -> name + ": tests found"), () -> assertEquals(0, summary.getTestsSkippedCount(), () -> name + ": tests skipped"), () -> assertEquals(0, summary.getTestsAbortedCount(), () -> name + ": tests aborted"), () -> assertEquals(expectedStartedCount, summary.getTestsStartedCount(), () -> name + ": tests started"), () -> assertEquals(expectedSucceededCount, summary.getTestsSucceededCount(), () -> name + ": tests succeeded"), () -> assertEquals(expectedFailedCount, summary.getTestsFailedCount(), () -> name + ": tests failed"));
// something else like an error in the @Configuration class, etc.
if (expectedFailedCount > 0) {
assertEquals(1, listener.exceptions.size(), "exceptions expected");
Throwable exception = listener.exceptions.get(0);
if (!(exception instanceof AssertionFailedError)) {
throw new AssertionFailedError(exception.getClass().getName() + " is not an instance of " + AssertionFailedError.class.getName(), exception);
}
}
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class ConsoleTestExecutor method executeTests.
private TestExecutionSummary executeTests(PrintWriter out) {
Launcher launcher = launcherSupplier.get();
SummaryGeneratingListener summaryListener = registerListeners(out, launcher);
LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator().toDiscoveryRequest(options);
launcher.execute(discoveryRequest);
TestExecutionSummary summary = summaryListener.getSummary();
if (summary.getTotalFailureCount() > 0 || options.getDetails() != Details.NONE) {
printSummary(summary, out);
}
return summary;
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformRunnerTests method instantiateRunnerAndCaptureGeneratedRequest.
private LauncherDiscoveryRequest instantiateRunnerAndCaptureGeneratedRequest(Class<?> testClass) throws InitializationError {
Launcher launcher = mock(Launcher.class);
ArgumentCaptor<LauncherDiscoveryRequest> captor = ArgumentCaptor.forClass(LauncherDiscoveryRequest.class);
when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(emptySet()));
new JUnitPlatform(testClass, launcher);
return captor.getValue();
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformProviderTests method allGivenTestsToRunAreInvoked.
@Test
void allGivenTestsToRunAreInvoked() throws Exception {
Launcher launcher = LauncherFactory.create();
JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
launcher.registerTestExecutionListeners(executionListener);
TestsToRun testsToRun = newTestsToRun(TestClass1.class, TestClass2.class);
invokeProvider(provider, testsToRun);
assertThat(executionListener.summaries).hasSize(1);
TestExecutionSummary summary = executionListener.summaries.get(0);
assertEquals(TestClass1.TESTS_FOUND + TestClass2.TESTS_FOUND, summary.getTestsFoundCount());
assertEquals(TestClass1.TESTS_STARTED + TestClass2.TESTS_STARTED, summary.getTestsStartedCount());
assertEquals(TestClass1.TESTS_SKIPPED + TestClass2.TESTS_SKIPPED, summary.getTestsSkippedCount());
assertEquals(TestClass1.TESTS_SUCCEEDED + TestClass2.TESTS_SUCCEEDED, summary.getTestsSucceededCount());
assertEquals(TestClass1.TESTS_ABORTED + TestClass2.TESTS_ABORTED, summary.getTestsAbortedCount());
assertEquals(TestClass1.TESTS_FAILED + TestClass2.TESTS_FAILED, summary.getTestsFailedCount());
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformProviderTests method outputIsCaptured.
@Test
void outputIsCaptured() throws Exception {
Launcher launcher = LauncherFactory.create();
RunListener runListener = runListenerMock();
JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(runListener), launcher);
invokeProvider(provider, VerboseTestClass.class);
ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
// @formatter:off
verify((ConsoleOutputReceiver) runListener).writeTestOutput(captor.capture(), eq(0), gt(6), eq(true));
verify((ConsoleOutputReceiver) runListener).writeTestOutput(captor.capture(), eq(0), gt(6), eq(false));
assertThat(captor.getAllValues()).extracting(bytes -> new String(bytes, 0, 6)).containsExactly("stdout", "stderr");
// @formatter:on
}
Aggregations