Search in sources :

Example 86 with LauncherDiscoveryRequest

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));
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) Launcher(org.junit.platform.launcher.Launcher) LoggingListener(org.junit.platform.launcher.listeners.LoggingListener)

Example 87 with LauncherDiscoveryRequest

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);
    }
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) PrintStream(java.io.PrintStream) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) ArrayList(java.util.ArrayList) AntClassLoader(org.apache.tools.ant.AntClassLoader) Launcher(org.junit.platform.launcher.Launcher) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException)

Example 88 with LauncherDiscoveryRequest

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));
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichIsIgnored(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichIsIgnored) JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored(org.junit.vintage.engine.samples.junit4.JUnit4SuiteWithPlainJUnit4TestCaseWithSingleTestWhichIsIgnored) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 89 with LauncherDiscoveryRequest

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
}
Also used : Path(java.nio.file.Path) PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Example 90 with LauncherDiscoveryRequest

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
}
Also used : Path(java.nio.file.Path) PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) TestDescriptor(org.junit.platform.engine.TestDescriptor) PlainOldJavaClassWithoutAnyTest(org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest) Test(org.junit.jupiter.api.Test)

Aggregations

LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)158 Test (org.junit.jupiter.api.Test)141 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)74 TestDescriptor (org.junit.platform.engine.TestDescriptor)54 PlainOldJavaClassWithoutAnyTest (org.junit.vintage.engine.samples.PlainOldJavaClassWithoutAnyTest)33 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)11 DiscoverySelectors.selectMethod (org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod)11 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)11 Method (java.lang.reflect.Method)9 Launcher (org.junit.platform.launcher.Launcher)9 PlainJUnit4TestCaseWithSingleTestWhichFails (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)5 Path (java.nio.file.Path)4 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)4 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)4 TestIdentifier (org.junit.platform.launcher.TestIdentifier)4 TestPlan (org.junit.platform.launcher.TestPlan)4