org.junit.platform.engine.discovery.DiscoverySelectors Java Examples
The following examples show how to use
org.junit.platform.engine.discovery.DiscoverySelectors.
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: Junit5Build.java From jeka with Apache License 2.0 | 6 votes |
@Override protected void setup() { java.getProject() .getJarProduction() .getDependencyManagement() .addDependencies(JkDependencySet.of() .and("org.junit.jupiter:junit-jupiter-engine:5.1.0", TEST) .and("org.junit.vintage:junit-vintage-engine:jar:5.6.0", TEST) .and("org.jdom:jdom2:2.0.6", TEST) ).__ .getTesting() .getTestProcessor() .getEngineBehavior() .setLauncherConfigurer(builder -> builder // Junit5-platform API. see nit.org/junit5/docs/5.3.0/api/org/junit/platform/launcher/core/LauncherConfig.html .addTestExecutionListeners(new MyJunit5PlatformListener())).__.__ .getTestSelection() .setDiscoveryConfigurer(builder -> builder // see https://junit.org/junit5/docs/5.0.0/api/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.html .configurationParameter("key1", "value1") .selectors( DiscoverySelectors.selectMethod("dev.jeka.core.samples.FooTest#testDisplay"))); }
Example #2
Source File: AllureJunit5Test.java From allure-java with Apache License 2.0 | 5 votes |
@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 #3
Source File: AllureJunitPlatformTest.java From allure-java with Apache License 2.0 | 5 votes |
@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 #4
Source File: TestClassExecutor.java From webtester2-core with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public <T extends DiscoverySelector> List<T> getSelectorsByType(Class<T> selectorType) { if (ClassSelector.class.equals(selectorType)) { List<T> list = new ArrayList<>(); list.add(( T ) DiscoverySelectors.selectClass(testClass)); return list; } return Collections.emptyList(); }
Example #5
Source File: JunitRunner.java From vespa with Apache License 2.0 | 5 votes |
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 #6
Source File: TesterRunner.java From pro with GNU General Public License v3.0 | 5 votes |
private static int launchJUnitPlatform(TestConf testConf) { var moduleName = testConf.moduleName(); var moduleNameAndVersion = testConf.moduleNameAndVersion(); var parallel = testConf.parallel(); var includeTags = testConf.includeTags(); var excludeTags = testConf.excludeTags(); // Create Launcher API entry point // https://junit.org/junit5/docs/current/user-guide/#launcher-api var builder = LauncherDiscoveryRequestBuilder.request(); // Select from... var packages = testConf.packages(); if (packages.isEmpty()) { builder.selectors(selectModule(moduleName)); } else { builder.selectors(packages.stream().map(DiscoverySelectors::selectPackage).collect(toUnmodifiableList())); } // Apply filters... if (!includeTags.isEmpty()) { builder.filters(TagFilter.includeTags(includeTags)); } if (!excludeTags.isEmpty()) { builder.filters(TagFilter.excludeTags(excludeTags)); } // Fine-tune configuration... builder.configurationParameter("junit.jupiter.execution.parallel.enabled", Boolean.toString(parallel)); var launcher = LauncherFactory.create(); var launcherDiscoveryRequest = builder.build(); var summaryGeneratingListener = new SummaryGeneratingListener(); var xmlReportsWritingListener = new LegacyXmlReportGeneratingListener(testConf.reportPath().resolve(moduleName), new PrintWriter(System.out)); launcher.registerTestExecutionListeners(summaryGeneratingListener); launcher.registerTestExecutionListeners(xmlReportsWritingListener); var startTimeMillis = System.currentTimeMillis(); launcher.execute(launcherDiscoveryRequest); var duration = System.currentTimeMillis() - startTimeMillis; var summary = summaryGeneratingListener.getSummary(); // DEBUG //summary.printTo(new PrintWriter(System.out)); var success = summary.getTestsFailedCount() == 0 && summary.getTestsAbortedCount() == 0 && summary.getContainersFailedCount() == 0 && summary.getContainersAbortedCount() == 0; if (success) { var succeeded = summary.getTestsSucceededCount(); System.out.printf("[tester] Successfully tested %s: %d tests in %d ms%n", moduleNameAndVersion, succeeded, duration); } else { var writer = new PrintWriter(System.err); summary.printTo(writer); summary.printFailuresTo(writer); } return success? 0: 1; }
Example #7
Source File: EngineDiscoveryTestRequest.java From ArchUnit with Apache License 2.0 | 4 votes |
private List<ClasspathRootSelector> createClasspathRootSelectors(List<URI> classpathRootsToDiscover) { return DiscoverySelectors.selectClasspathRoots(classpathRootsToDiscover.stream().map(Paths::get).collect(toSet())); }
Example #8
Source File: EngineDiscoveryTestRequest.java From ArchUnit with Apache License 2.0 | 4 votes |
private List<PackageSelector> createPackageSelectors(List<String> packagesToDiscover) { return packagesToDiscover.stream().map(DiscoverySelectors::selectPackage).collect(toList()); }
Example #9
Source File: EngineDiscoveryTestRequest.java From ArchUnit with Apache License 2.0 | 4 votes |
private List<ClassSelector> createClassSelectors(List<Class<?>> classesToDiscover) { return classesToDiscover.stream().map(DiscoverySelectors::selectClass).collect(toList()); }
Example #10
Source File: EngineDiscoveryTestRequest.java From ArchUnit with Apache License 2.0 | 4 votes |
private List<UniqueIdSelector> createUniqueIdSelectors(List<UniqueId> idsToDiscover) { return idsToDiscover.stream().map(DiscoverySelectors::selectUniqueId).collect(toList()); }