Java源码示例:org.junit.platform.launcher.core.LauncherConfig

示例1
@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);
    }
}
 
示例2
@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);
    }
}
 
示例3
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);
}
 
示例4
public JkUnaryOperator<LauncherConfig.Builder> getLauncherConfigurer() {
    return launcherConfigurer;
}
 
示例5
/**
 * 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;
}