use of org.junit.platform.launcher.LauncherDiscoveryRequest in project narchy by automenta.
the class NARTestBenchmark method junit.
// @Benchmark
// @BenchmarkMode(Mode.AverageTime)
// @Fork(1)
// public void testY() {
// The.Compound.the = FastCompound.FAST_COMPOUND_BUILDER;
// // Param.SynchronousExecution_Max_CycleTime = 0.0001f;
//
// junit(testclass);
// }
static void junit(Class... testClasses) {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(// selectPackage("com.example.mytests"),
(ClassSelector[]) Util.map(DiscoverySelectors::selectClass, new ClassSelector[testClasses.length], testClasses)).build();
Launcher launcher = LauncherFactory.create();
// SummaryGeneratingListener listener = new SummaryGeneratingListener();
LoggingListener listener = LoggingListener.forJavaUtilLogging();
launcher.registerTestExecutionListeners(listener);
launcher.execute(request, listener);
// listener.getSummary().printTo(new PrintWriter(System.out));
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project ant by apache.
the class JUnitLauncherTask method execute.
@Override
public void execute() throws BuildException {
final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
try {
final ClassLoader executionCL = createClassLoaderForTestExecution();
Thread.currentThread().setContextClassLoader(executionCL);
final Launcher launcher = LauncherFactory.create();
final List<TestRequest> requests = buildTestRequests();
for (final TestRequest testRequest : requests) {
try {
final TestDefinition test = testRequest.getOwner();
final LauncherDiscoveryRequest request = testRequest.getDiscoveryRequest().build();
final List<TestExecutionListener> testExecutionListeners = new ArrayList<>();
// a listener that we always put at the front of list of listeners
// for this request.
final Listener firstListener = new Listener();
// we always enroll the summary generating listener, to the request, so that we
// get to use some of the details of the summary for our further decision making
testExecutionListeners.add(firstListener);
testExecutionListeners.addAll(getListeners(testRequest, executionCL));
final PrintStream originalSysOut = System.out;
final PrintStream originalSysErr = System.err;
try {
firstListener.switchedSysOutHandle = trySwitchSysOutErr(testRequest, StreamType.SYS_OUT);
firstListener.switchedSysErrHandle = trySwitchSysOutErr(testRequest, StreamType.SYS_ERR);
launcher.execute(request, testExecutionListeners.toArray(new TestExecutionListener[testExecutionListeners.size()]));
} finally {
// switch back sysout/syserr to the original
try {
System.setOut(originalSysOut);
} catch (Exception e) {
// ignore
}
try {
System.setErr(originalSysErr);
} catch (Exception e) {
// ignore
}
}
handleTestExecutionCompletion(test, firstListener.getSummary());
} finally {
try {
testRequest.close();
} catch (Exception e) {
// log and move on
log("Failed to cleanly close test request", e, Project.MSG_DEBUG);
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(previousClassLoader);
}
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesJUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored.
@Test
void resolvesJUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored() throws Exception {
Class<?> suiteClass = JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored.class;
Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichIsIgnored.class;
LauncherDiscoveryRequest discoveryRequest = discoveryRequestForClass(suiteClass);
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
TestDescriptor suiteDescriptor = getOnlyElement(engineDescriptor.getChildren());
assertRunnerTestDescriptor(suiteDescriptor, suiteClass);
TestDescriptor testClassDescriptor = getOnlyElement(suiteDescriptor.getChildren());
assertContainerTestDescriptor(testClassDescriptor, suiteClass, testClass);
TestDescriptor testMethodDescriptor = getOnlyElement(testClassDescriptor.getChildren());
assertTestMethodDescriptor(testMethodDescriptor, testClass, "ignoredTest", VintageUniqueIdBuilder.uniqueIdForClasses(suiteClass, testClass));
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesApplyingPackageNameFilters.
@Test
void resolvesApplyingPackageNameFilters() throws Exception {
Path root = getClasspathRoot(PlainJUnit4TestCaseWithSingleTestWhichFails.class);
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClasspathRoots(singleton(root))).filters(includePackageNames("org"), includePackageNames("org.junit")).build();
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
// @formatter:off
assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).contains(PlainJUnit4TestCaseWithSingleTestWhichFails.class.getName());
// @formatter:on
}
use of org.junit.platform.launcher.LauncherDiscoveryRequest in project junit5 by junit-team.
the class VintageTestEngineDiscoveryTests method resolvesClasspathSelector.
@Test
void resolvesClasspathSelector() throws Exception {
Path root = getClasspathRoot(PlainJUnit4TestCaseWithSingleTestWhichFails.class);
LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClasspathRoots(singleton(root))).build();
TestDescriptor engineDescriptor = discoverTests(discoveryRequest);
// @formatter:off
assertThat(engineDescriptor.getChildren()).extracting(TestDescriptor::getDisplayName).contains(PlainJUnit4TestCaseWithSingleTestWhichFails.class.getName()).contains(PlainJUnit3TestCaseWithSingleTestWhichFails.class.getName()).doesNotContain(PlainOldJavaClassWithoutAnyTest.class.getName());
// @formatter:on
}
Aggregations