use of org.junit.platform.launcher.listeners.SummaryGeneratingListener in project junit5 by junit-team.
the class ConsoleTestExecutor method registerListeners.
private SummaryGeneratingListener registerListeners(PrintWriter out, Launcher launcher) {
// always register summary generating listener
SummaryGeneratingListener summaryListener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(summaryListener);
// optionally, register test plan execution details printing listener
createDetailsPrintingListener(out).ifPresent(launcher::registerTestExecutionListeners);
// optionally, register XML reports writing listener
createXmlWritingListener(out).ifPresent(launcher::registerTestExecutionListeners);
return summaryListener;
}
use of org.junit.platform.launcher.listeners.SummaryGeneratingListener 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.listeners.SummaryGeneratingListener in project junit5 by junit-team.
the class DefaultLauncherTests method withAdditionalListener.
@Test
void withAdditionalListener() {
TestEngineSpy engine = new TestEngineSpy();
SummaryGeneratingListener listener = new SummaryGeneratingListener();
DefaultLauncher launcher = createLauncher(engine);
launcher.execute(request().build(), listener);
assertThat(listener.getSummary()).isNotNull();
assertThat(listener.getSummary().getContainersFoundCount()).isEqualTo(1);
assertThat(listener.getSummary().getTestsFoundCount()).isEqualTo(1);
}
use of org.junit.platform.launcher.listeners.SummaryGeneratingListener in project junit5 by junit-team.
the class MyTestClass method execution.
@org.junit.jupiter.api.Test
void execution() {
// @formatter:off
// tag::execution[]
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
Launcher launcher = LauncherFactory.create();
// Register a listener of your choice
TestExecutionListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);
// end::execution[]
// @formatter:on
}
use of org.junit.platform.launcher.listeners.SummaryGeneratingListener in project tutorials by eugenp.
the class TestLauncher method main.
public static void main(String[] args) {
// @formatter:off
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectClass("com.baeldung.EmployeesTest")).configurationParameter("junit.conditions.deactivate", "com.baeldung.extensions.*").configurationParameter("junit.extensions.autodetection.enabled", "true").build();
// @formatter:on
TestPlan plan = LauncherFactory.create().discover(request);
Launcher launcher = LauncherFactory.create();
SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
launcher.execute(request, new TestExecutionListener[] { summaryGeneratingListener });
launcher.execute(request);
summaryGeneratingListener.getSummary().printTo(new PrintWriter(System.out));
}
Aggregations