Search in sources :

Example 6 with Launcher

use of org.junit.platform.launcher.Launcher 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 7 with Launcher

use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.

the class MyTestClass method discovery.

@org.junit.jupiter.api.Test
@SuppressWarnings("unused")
void discovery() {
    // @formatter:off
    // tag::discovery[]
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
    Launcher launcher = LauncherFactory.create();
    TestPlan testPlan = launcher.discover(request);
// end::discovery[]
// @formatter:on
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan) Launcher(org.junit.platform.launcher.Launcher)

Example 8 with Launcher

use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.

the class JUnit4ParameterizedTests method executeTests.

private void executeTests(DiscoverySelector selector) {
    Launcher launcher = LauncherFactory.create();
    launcher.registerTestExecutionListeners(new StatusTrackingListener());
    // @formatter:off
    launcher.execute(request().selectors(selector).filters(includeEngines("junit-vintage")).build());
// @formatter:on
}
Also used : Launcher(org.junit.platform.launcher.Launcher)

Example 9 with Launcher

use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.

the class VintageLauncherIntegrationTests method execute.

private Map<TestIdentifier, TestExecutionResult> execute(LauncherDiscoveryRequestBuilder requestBuilder) {
    Map<TestIdentifier, TestExecutionResult> results = new LinkedHashMap<>();
    LauncherDiscoveryRequest request = toRequest(requestBuilder);
    Launcher launcher = LauncherFactory.create();
    launcher.execute(request, new TestExecutionListener() {

        @Override
        public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
            results.put(testIdentifier, testExecutionResult);
        }
    });
    return results;
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) Launcher(org.junit.platform.launcher.Launcher) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) LinkedHashMap(java.util.LinkedHashMap)

Example 10 with Launcher

use of org.junit.platform.launcher.Launcher 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

Launcher (org.junit.platform.launcher.Launcher)26 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)16 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)8 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)7 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 TestPlan (org.junit.platform.launcher.TestPlan)6 Test (org.junit.jupiter.api.Test)5 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)3 TestIdentifier (org.junit.platform.launcher.TestIdentifier)3 PrintStream (java.io.PrintStream)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 RunListener (org.apache.maven.surefire.report.RunListener)2 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)2 TestListResolver (org.apache.maven.surefire.testset.TestListResolver)2 TestsToRun (org.apache.maven.surefire.util.TestsToRun)2 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1