use of org.junit.platform.launcher.LauncherSession in project junit5 by junit-team.
the class CustomPostDiscoveryFilter method execution.
@org.junit.jupiter.api.Test
@SuppressWarnings("unused")
void execution() {
// @formatter:off
// tag::execution[]
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
SummaryGeneratingListener listener = new SummaryGeneratingListener();
try (LauncherSession session = LauncherFactory.openSession()) {
Launcher launcher = session.getLauncher();
// Register a listener of your choice
launcher.registerTestExecutionListeners(listener);
// Discover tests and build a test plan
TestPlan testPlan = launcher.discover(request);
// Execute test plan
launcher.execute(testPlan);
// Alternatively, execute the request directly
launcher.execute(request);
}
TestExecutionSummary summary = listener.getSummary();
// Do something with the summary...
// end::execution[]
// @formatter:on
}
use of org.junit.platform.launcher.LauncherSession in project junit5 by junit-team.
the class CustomPostDiscoveryFilter method launcherConfig.
@org.junit.jupiter.api.Test
void launcherConfig() {
Path reportsDir = Paths.get("target", "xml-reports");
PrintWriter out = new PrintWriter(System.out);
// @formatter:off
// tag::launcherConfig[]
LauncherConfig launcherConfig = LauncherConfig.builder().enableTestEngineAutoRegistration(false).enableLauncherSessionListenerAutoRegistration(false).enableLauncherDiscoveryListenerAutoRegistration(false).enablePostDiscoveryFilterAutoRegistration(false).enableTestExecutionListenerAutoRegistration(false).addTestEngines(new CustomTestEngine()).addLauncherSessionListeners(new CustomLauncherSessionListener()).addLauncherDiscoveryListeners(new CustomLauncherDiscoveryListener()).addPostDiscoveryFilters(new CustomPostDiscoveryFilter()).addTestExecutionListeners(new LegacyXmlReportGeneratingListener(reportsDir, out)).addTestExecutionListeners(new CustomTestExecutionListener()).build();
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests")).build();
try (LauncherSession session = LauncherFactory.openSession(launcherConfig)) {
session.getLauncher().execute(request);
}
// end::launcherConfig[]
// @formatter:on
}
Aggregations