Search in sources :

Example 1 with SummaryGeneratingListener

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;
}
Also used : SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener)

Example 2 with SummaryGeneratingListener

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

Example 3 with SummaryGeneratingListener

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);
}
Also used : SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 4 with SummaryGeneratingListener

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

Example 5 with SummaryGeneratingListener

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

Aggregations

SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)6 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)4 Launcher (org.junit.platform.launcher.Launcher)3 Test (org.junit.jupiter.api.Test)2 PrintWriter (java.io.PrintWriter)1 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)1 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)1 TestPlan (org.junit.platform.launcher.TestPlan)1 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)1