Search in sources :

Example 1 with LauncherSession

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
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestPlan(org.junit.platform.launcher.TestPlan) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) LauncherSession(org.junit.platform.launcher.LauncherSession)

Example 2 with LauncherSession

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
}
Also used : Path(java.nio.file.Path) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) LegacyXmlReportGeneratingListener(org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener) LauncherConfig(org.junit.platform.launcher.core.LauncherConfig) PrintWriter(java.io.PrintWriter) LauncherSession(org.junit.platform.launcher.LauncherSession)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)2 LauncherSession (org.junit.platform.launcher.LauncherSession)2 PrintWriter (java.io.PrintWriter)1 Path (java.nio.file.Path)1 Launcher (org.junit.platform.launcher.Launcher)1 TestPlan (org.junit.platform.launcher.TestPlan)1 LauncherConfig (org.junit.platform.launcher.core.LauncherConfig)1 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)1 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)1 LegacyXmlReportGeneratingListener (org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener)1