org.junit.platform.launcher.core.LauncherConfig Java Examples

The following examples show how to use org.junit.platform.launcher.core.LauncherConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureJunit5Test.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .configurationParameter("junit.jupiter.extensions.autodetection.enabled", "true")
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example #2
Source File: AllureJunitPlatformTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Step("Run classes {classes}")
private AllureResults runClasses(final Class<?>... classes) {
    final AllureResultsWriterStub writerStub = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writerStub);

    final ClassSelector[] classSelectors = Stream.of(classes)
            .map(DiscoverySelectors::selectClass)
            .toArray(ClassSelector[]::new);

    final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(classSelectors)
            .build();

    final LauncherConfig config = LauncherConfig.builder()
            .enableTestExecutionListenerAutoRegistration(false)
            .addTestExecutionListeners(new AllureJunitPlatform(lifecycle))
            .build();
    final Launcher launcher = LauncherFactory.create(config);

    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    try {
        Allure.setLifecycle(lifecycle);
        StepsAspects.setLifecycle(lifecycle);
        AttachmentsAspects.setLifecycle(lifecycle);
        launcher.execute(request);
        return writerStub;
    } finally {
        Allure.setLifecycle(defaultLifecycle);
        StepsAspects.setLifecycle(defaultLifecycle);
        AttachmentsAspects.setLifecycle(defaultLifecycle);
    }
}
 
Example #3
Source File: JunitRunner.java    From vespa with Apache License 2.0 5 votes vote down vote up
public String executeTests(List<Class<?>> testClasses) {
    LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request()
            .selectors(
                    testClasses.stream().map(DiscoverySelectors::selectClass).collect(Collectors.toList())
            )
            .build();

    var launcherConfig = LauncherConfig.builder()
            .addTestEngines(new JupiterTestEngine())

            .build();
    Launcher launcher = LauncherFactory.create(launcherConfig);

    // Create log listener:
    var logLines = new ArrayList<String>();
    var logListener = LoggingListener.forBiConsumer((t, m) -> log(logLines, m.get(), t));
    // Create a summary listener:
    var summaryListener = new SummaryGeneratingListener();
    launcher.registerTestExecutionListeners(logListener, summaryListener);

    // Execute request
    launcher.execute(discoveryRequest);

    var report = summaryListener.getSummary();

    return createJsonTestReport(report, logLines);
}
 
Example #4
Source File: JkTestProcessor.java    From jeka with Apache License 2.0 4 votes vote down vote up
public JkUnaryOperator<LauncherConfig.Builder> getLauncherConfigurer() {
    return launcherConfigurer;
}
 
Example #5
Source File: JkTestProcessor.java    From jeka with Apache License 2.0 2 votes vote down vote up
/**
 * Lets to setup the Junit-platform native {@link LauncherConfig} used to build
 * the {@link org.junit.platform.launcher.Launcher}.
 * @param launcherConfigurer a function that takes the default {@link LauncherConfig} as argument
 *                          and returns the config to use.
 */
public JkEngineBehavior<T> setLauncherConfigurer(JkUnaryOperator<LauncherConfig.Builder> launcherConfigurer) {
    this.launcherConfigurer = launcherConfigurer;
    return this;
}