Search in sources :

Example 11 with Launcher

use of org.junit.platform.launcher.Launcher in project mockito by mockito.

the class StrictnessTest method invokeTestClassAndRetrieveMethodResult.

private TestExecutionResult invokeTestClassAndRetrieveMethodResult(Class<?> clazz) {
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectClass(clazz)).build();
    Launcher launcher = LauncherFactory.create();
    final TestExecutionResult[] result = new TestExecutionResult[1];
    launcher.registerTestExecutionListeners(new TestExecutionListener() {

        @Override
        public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
            if (testIdentifier.getDisplayName().endsWith("()")) {
                result[0] = testExecutionResult;
            }
        }
    });
    launcher.execute(request);
    return result[0];
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) Launcher(org.junit.platform.launcher.Launcher) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestExecutionResult(org.junit.platform.engine.TestExecutionResult)

Example 12 with Launcher

use of org.junit.platform.launcher.Launcher in project neo4j by neo4j.

the class ProfilerExtensionTest method execute.

private static void execute(Class<?> testClass, String testName, TestExecutionListener... testExecutionListeners) {
    LauncherDiscoveryRequest discoveryRequest = LauncherDiscoveryRequestBuilder.request().selectors(selectMethod(testClass, testName)).configurationParameter(TEST_TOGGLE, "true").build();
    Launcher launcher = LauncherFactory.create();
    launcher.execute(discoveryRequest, testExecutionListeners);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) Launcher(org.junit.platform.launcher.Launcher)

Example 13 with Launcher

use of org.junit.platform.launcher.Launcher in project spring-boot by spring-projects.

the class ModifiedClassPathExtension method runTest.

private void runTest(ClassLoader classLoader, String testClassName, String testMethodName) throws Throwable {
    Class<?> testClass = classLoader.loadClass(testClassName);
    Method testMethod = findMethod(testClass, testMethodName);
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(DiscoverySelectors.selectMethod(testClass, testMethod)).build();
    Launcher launcher = LauncherFactory.create();
    TestPlan testPlan = launcher.discover(request);
    SummaryGeneratingListener listener = new SummaryGeneratingListener();
    launcher.registerTestExecutionListeners(listener);
    launcher.execute(testPlan);
    TestExecutionSummary summary = listener.getSummary();
    if (!CollectionUtils.isEmpty(summary.getFailures())) {
        throw summary.getFailures().get(0).getException();
    }
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) TestPlan(org.junit.platform.launcher.TestPlan) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) Method(java.lang.reflect.Method)

Example 14 with Launcher

use of org.junit.platform.launcher.Launcher in project spring-framework by spring-projects.

the class ParallelExecutionSpringExtensionTests method runTestsInParallel.

@RepeatedTest(10)
void runTestsInParallel() {
    Launcher launcher = LauncherFactory.create();
    SummaryGeneratingListener listener = new SummaryGeneratingListener();
    launcher.registerTestExecutionListeners(listener);
    LauncherDiscoveryRequest request = // 
    request().configurationParameter("junit.jupiter.conditions.deactivate", // 
    "org.junit.jupiter.engine.extension.DisabledCondition").configurationParameter("junit.jupiter.execution.parallel.enabled", // 
    "true").configurationParameter("junit.jupiter.execution.parallel.config.dynamic.factor", // 
    "10").selectors(// 
    selectClass(TestCase.class)).build();
    launcher.execute(request);
    assertThat(listener.getSummary().getTestsSucceededCount()).as("number of tests executed successfully").isEqualTo(NUM_TESTS);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) Launcher(org.junit.platform.launcher.Launcher) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 15 with Launcher

use of org.junit.platform.launcher.Launcher 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)

Aggregations

Launcher (org.junit.platform.launcher.Launcher)26 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)16 TestExecutionSummary (org.junit.platform.launcher.listeners.TestExecutionSummary)8 SummaryGeneratingListener (org.junit.platform.launcher.listeners.SummaryGeneratingListener)7 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)6 TestPlan (org.junit.platform.launcher.TestPlan)6 Test (org.junit.jupiter.api.Test)5 ProviderParameters (org.apache.maven.surefire.providerapi.ProviderParameters)3 TestIdentifier (org.junit.platform.launcher.TestIdentifier)3 PrintStream (java.io.PrintStream)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 RunListener (org.apache.maven.surefire.report.RunListener)2 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)2 TestListResolver (org.apache.maven.surefire.testset.TestListResolver)2 TestsToRun (org.apache.maven.surefire.util.TestsToRun)2 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1