Java 类org.junit.platform.launcher.LauncherDiscoveryRequest 实例源码
项目:mastering-junit5
文件:LauncherApiExample.java
@SuppressWarnings("unused")
public static void main(String[] args) {
// Discover and filter tests
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(selectPackage("io.github.bonigarcia"),
selectClass(DummyTest.class))
.filters(includeClassNamePatterns(".*Test")).build();
Launcher launcher = LauncherFactory.create();
TestPlan plan = launcher.discover(request);
// Executing tests
TestExecutionListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request, listener);
}
项目:Mastering-Software-Testing-with-JUnit-5
文件:LauncherApiExample.java
@SuppressWarnings("unused")
public static void main(String[] args) {
// Discover and filter tests
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder
.request()
.selectors(selectPackage("io.github.bonigarcia"),
selectClass(DummyTest.class))
.filters(includeClassNamePatterns(".*Test")).build();
Launcher launcher = LauncherFactory.create();
TestPlan plan = launcher.discover(request);
// Executing tests
TestExecutionListener listener = new SummaryGeneratingListener();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request, listener);
}
项目:junit-extensions
文件:ExtensionTester.java
/**
* Instance an engine and execute the test resources identified by the given {@code selectors} and
* wrap the response in a listener so that we can make sense of what happened. The listener
* exposes information about the test execution flow which the extension tests can assert against.
*
* @param selectors {@link DiscoverySelector} instances which will isolate test class or test
* methods
* @return a {@link RecordingExecutionListener} which encapsulates what the engine did
*/
public static RecordingExecutionListener execute(DiscoverySelector... selectors) {
// instance an engine
JupiterTestEngine testEngine = new JupiterTestEngine();
// discover the requested test resources
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectors).build();
RecordingExecutionListener listener = new RecordingExecutionListener();
// execute the discovered test resources
TestDescriptor testDescriptor =
testEngine.discover(discoveryRequest, UniqueId.forEngine(testEngine.getId()));
testEngine.execute(
new ExecutionRequest(
testDescriptor, listener, discoveryRequest.getConfigurationParameters()));
return listener;
}
项目:jovial
文件:JovialSocketLauncher.java
public static void main(String[] args) throws Exception {
try (SocketChannel channel = openSocket()) {
TestExecutionListener listener = createListener(channel);
Launcher launcher = LauncherFactory.create();
launcher.registerTestExecutionListeners(listener);
ObjectInputStream inputStream = openInput();
Map<String, List<String>> config = (Map<String, List<String>>) inputStream.readObject();
Set<File> roots = config.get("classpathRoots").stream()
.map(File::new)
.collect(Collectors.toSet());
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClasspathRoots(roots))
.build();
launcher.execute(request);
}
}
项目:pro
文件:TesterRunner.java
private static int launch(ModuleReference moduleReference, Launcher launcher) {
LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request();
builder.selectors(selectModule(moduleReference.descriptor().name()));
long startTimeMillis = System.currentTimeMillis();
LauncherDiscoveryRequest launcherDiscoveryRequest = builder.build();
SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
launcher.execute(launcherDiscoveryRequest, summaryGeneratingListener);
long duration = System.currentTimeMillis() - startTimeMillis;
TestExecutionSummary summary = summaryGeneratingListener.getSummary();
int failures = (int) summary.getTestsFailedCount();
if (failures == 0) {
long succeeded = summary.getTestsSucceededCount();
String moduleName = moduleReference.descriptor().toNameAndVersion();
System.out.printf("[tester] Successfully tested %s: %d tests in %d ms%n", moduleName, succeeded, duration);
} else {
StringWriter stringWriter = new StringWriter();
summary.printTo(new PrintWriter(stringWriter));
summary.printFailuresTo(new PrintWriter(stringWriter));
System.out.println(stringWriter);
}
return failures;
}
项目:allure-java
文件:AnnotationsTest.java
private void runClasses(Class<?>... classes) {
final ClassSelector[] classSelectors = Stream.of(classes)
.map(DiscoverySelectors::selectClass)
.toArray(ClassSelector[]::new);
final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(classSelectors)
.build();
AllureJunit5AnnotationProcessor.setLifecycle(lifecycle);
final Launcher launcher = LauncherFactory.create();
launcher.execute(request, new AllureJunit5(lifecycle));
}
项目:allure-java
文件:AllureJunit5Test.java
private void runClasses(Class<?>... classes) {
final ClassSelector[] classSelectors = Stream.of(classes)
.map(DiscoverySelectors::selectClass)
.toArray(ClassSelector[]::new);
final LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(classSelectors)
.build();
final Launcher launcher = LauncherFactory.create();
launcher.execute(request, new AllureJunit5(lifecycle));
}
项目:junit5-extensions
文件:ExtensionTester.java
public static TestPlanExecutionReport runTests(Class<?> clazz) {
Launcher launcher = LauncherFactory.create();
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectClass(clazz))
.build();
ExecutionReportListener listener = new ExecutionReportListener().addClassToSkip(clazz);
launcher.execute(request, listener);
return listener.getReport();
}
项目:verify-matching-service-adapter
文件:Application.java
public ExitStatus execute(SummaryGeneratingListener listener,
DiscoverySelector selector,
ApplicationConfiguration applicationConfiguration,
FilesLocator filesLocator) {
ApplicationConfigurationResolver.setConfiguration(applicationConfiguration);
FilesLocatorResolver.setFilesLocator(filesLocator);
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(selector)
.build();
Launcher launcher = LauncherFactory.create();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);
return listener.getSummary().getFailures().isEmpty() ? ExitStatus.SUCCESS : ExitStatus.FAILURE;
}
项目:junit5-docker
文件:JupiterTestEngineForTests.java
private JupiterExecutionListener executeTests(LauncherDiscoveryRequest request) throws Exception {
TestDescriptor testDescriptor = createTestDescriptorForCucumber(
engine.discover(request, forEngine(engine.getId())), containers);
eventRecorder.reset();
engine.execute(new ExecutionRequest(testDescriptor, eventRecorder, request.getConfigurationParameters()));
return eventRecorder;
}
项目:junit-pioneer
文件:AbstractPioneerTestEngineTests.java
private ExecutionEventRecorder executeTestMethods(Class<?> type, String[] methodNames) {
//@formatter:off
DiscoverySelector[] selectors = stream(methodNames)
.map(methodName -> selectMethod(type, methodName))
.toArray(DiscoverySelector[]::new);
//@formatter:on
LauncherDiscoveryRequest request = request().selectors(selectors).build();
return executeTests(request);
}
项目:pitest-junit5-plugin
文件:ForeignClassLoaderLauncher.java
public ForeignClassLoaderLauncher(Launcher launcher, LauncherDiscoveryRequest launcherDiscoveryRequest) {
this.launcher = launcher;
this.launcherDiscoveryRequest = launcherDiscoveryRequest;
}
项目:junit-pioneer
文件:AbstractJupiterTestEngineTests.java
protected ExecutionEventRecorder executeTests(LauncherDiscoveryRequest request) {
TestDescriptor testDescriptor = discoverTests(request);
ExecutionEventRecorder eventRecorder = new ExecutionEventRecorder();
engine.execute(new ExecutionRequest(testDescriptor, eventRecorder, request.getConfigurationParameters()));
return eventRecorder;
}
项目:junit-pioneer
文件:AbstractJupiterTestEngineTests.java
protected TestDescriptor discoverTests(LauncherDiscoveryRequest request) {
return engine.discover(request, UniqueId.forEngine(engine.getId()));
}
项目:junit-pioneer
文件:AbstractPioneerTestEngineTests.java
private ExecutionEventRecorder executeTestClass(Class<?> type) {
LauncherDiscoveryRequest request = request().selectors(selectClass(type)).build();
return executeTests(request);
}