use of org.junit.platform.launcher.Launcher 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.Launcher in project junit5 by junit-team.
the class XmlReportsWritingListenerTests method executeTests.
private void executeTests(TestEngine engine, Path tempDirectory, Clock clock) {
PrintWriter out = new PrintWriter(new StringWriter());
XmlReportsWritingListener reportListener = new XmlReportsWritingListener(tempDirectory.toString(), out, clock);
Launcher launcher = createLauncher(engine);
launcher.registerTestExecutionListeners(reportListener);
launcher.execute(request().selectors(selectUniqueId(UniqueId.forEngine(engine.getId()))).build(), new TestExecutionListener[0]);
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformProviderTests method singleTestClassIsInvoked.
@Test
void singleTestClassIsInvoked() throws Exception {
Launcher launcher = LauncherFactory.create();
JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
launcher.registerTestExecutionListeners(executionListener);
invokeProvider(provider, TestClass1.class);
assertThat(executionListener.summaries).hasSize(1);
TestExecutionSummary summary = executionListener.summaries.get(0);
assertEquals(TestClass1.TESTS_FOUND, summary.getTestsFoundCount());
assertEquals(TestClass1.TESTS_STARTED, summary.getTestsStartedCount());
assertEquals(TestClass1.TESTS_SKIPPED, summary.getTestsSkippedCount());
assertEquals(TestClass1.TESTS_SUCCEEDED, summary.getTestsSucceededCount());
assertEquals(TestClass1.TESTS_ABORTED, summary.getTestsAbortedCount());
assertEquals(TestClass1.TESTS_FAILED, summary.getTestsFailedCount());
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformProviderTests method testExecutionOfMatchingTestMethods.
void testExecutionOfMatchingTestMethods(Class<?> testClass, String pattern, String... expectedTestNames) throws Exception {
TestListResolver testListResolver = new TestListResolver(pattern);
ProviderParameters providerParameters = providerParametersMock(testListResolver, testClass);
Launcher launcher = LauncherFactory.create();
JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher);
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
launcher.registerTestExecutionListeners(executionListener);
invokeProvider(provider, null);
assertEquals(1, executionListener.summaries.size());
TestExecutionSummary summary = executionListener.summaries.get(0);
int expectedCount = expectedTestNames.length;
assertEquals(expectedCount, summary.getTestsFoundCount());
assertEquals(expectedCount, summary.getTestsFailedCount());
assertEquals(expectedCount, summary.getFailures().size());
assertThat(failedTestDisplayNames(summary)).contains(expectedTestNames);
}
use of org.junit.platform.launcher.Launcher in project junit5 by junit-team.
the class JUnitPlatformProviderTests method allDiscoveredTestsAreInvokedForNullArgument.
@Test
void allDiscoveredTestsAreInvokedForNullArgument() throws Exception {
RunListener runListener = runListenerMock();
ProviderParameters providerParameters = providerParametersMock(runListener, TestClass1.class, TestClass2.class);
Launcher launcher = LauncherFactory.create();
JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher);
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
launcher.registerTestExecutionListeners(executionListener);
invokeProvider(provider, null);
InOrder inOrder = inOrder(runListener);
inOrder.verify(runListener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass1.class.getName()));
inOrder.verify(runListener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass1.class.getName()));
inOrder.verify(runListener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass2.class.getName()));
inOrder.verify(runListener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), TestClass2.class.getName()));
assertThat(executionListener.summaries).hasSize(1);
TestExecutionSummary summary = executionListener.summaries.get(0);
assertEquals(TestClass1.TESTS_FOUND + TestClass2.TESTS_FOUND, summary.getTestsFoundCount());
assertEquals(TestClass1.TESTS_STARTED + TestClass2.TESTS_STARTED, summary.getTestsStartedCount());
assertEquals(TestClass1.TESTS_SKIPPED + TestClass2.TESTS_SKIPPED, summary.getTestsSkippedCount());
assertEquals(TestClass1.TESTS_SUCCEEDED + TestClass2.TESTS_SUCCEEDED, summary.getTestsSucceededCount());
assertEquals(TestClass1.TESTS_ABORTED + TestClass2.TESTS_ABORTED, summary.getTestsAbortedCount());
assertEquals(TestClass1.TESTS_FAILED + TestClass2.TESTS_FAILED, summary.getTestsFailedCount());
}
Aggregations