use of org.junit.platform.launcher.TestPlan 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();
}
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class CustomPostDiscoveryFilter method execution.
@org.junit.jupiter.api.Test
@SuppressWarnings("unused")
void execution() {
// @formatter:off
// tag::execution[]
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example.mytests"), selectClass(MyTestClass.class)).filters(includeClassNamePatterns(".*Tests")).build();
SummaryGeneratingListener listener = new SummaryGeneratingListener();
try (LauncherSession session = LauncherFactory.openSession()) {
Launcher launcher = session.getLauncher();
// Register a listener of your choice
launcher.registerTestExecutionListeners(listener);
// Discover tests and build a test plan
TestPlan testPlan = launcher.discover(request);
// Execute test plan
launcher.execute(testPlan);
// Alternatively, execute the request directly
launcher.execute(request);
}
TestExecutionSummary summary = listener.getSummary();
// Do something with the summary...
// end::execution[]
// @formatter:on
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.
@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
var engine = new TestEngineSpy() {
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
super.discover(discoveryRequest, uniqueId);
var engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
var containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {
@Override
public Type getType() {
return Type.CONTAINER;
}
};
containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
engineDescriptor.addChild(containerDescriptor);
return engineDescriptor;
}
};
var launcher = createLauncher(engine);
var testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
assertThat(testPlan.getRoots()).hasSize(1);
var engineIdentifier = getOnlyElement(testPlan.getRoots());
assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
use of org.junit.platform.launcher.TestPlan in project intellij-community by JetBrains.
the class JUnit5EventsTest method containerFailure.
@Test
void containerFailure() throws Exception {
ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(UniqueId.forEngine("engine"), TestClass.class);
TestDescriptor testDescriptor = new TestFactoryTestDescriptor(UniqueId.forEngine("engine1"), TestClass.class, TestClass.class.getDeclaredMethod("brokenStream"));
TestIdentifier identifier = TestIdentifier.from(testDescriptor);
final TestPlan testPlan = TestPlan.from(Collections.singleton(classTestDescriptor));
myExecutionListener.sendTree(testPlan, "");
myExecutionListener.executionStarted(identifier);
myExecutionListener.executionFinished(identifier, TestExecutionResult.failed(new IllegalStateException()));
Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" + "##teamcity[treeEnded]\n" + "##teamcity[testSuiteStarted id='|[engine:engine1|]' name='brokenStream()']\n" + "\n" + "##teamcity[testStarted name='Class Configuration' locationHint='java:suite://com.intellij.junit5.JUnit5EventsTest$TestClass.brokenStream']\n" + "\n" + "##teamcity[testFailed name='Class Configuration' id='Class Configuration' details='TRACE' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='Class Configuration']\n" + "##teamcity[testSuiteFinished id='|[engine:engine1|]' name='brokenStream()']\n", StringUtil.convertLineSeparators(myBuf.toString()));
}
use of org.junit.platform.launcher.TestPlan in project junit5 by junit-team.
the class VintageLauncherIntegrationTests method removesCompleteClassIfItHasExcludedTag.
@Test
void removesCompleteClassIfItHasExcludedTag() {
Class<?> testClass = PlainJUnit4TestCaseWithFiveTestMethods.class;
LauncherDiscoveryRequestBuilder request = //
request().selectors(//
selectClass(testClass)).filters(excludeTags(Categories.Plain.class.getName()));
TestPlan testPlan = discover(request);
assertThat(testPlan.getDescendants(getOnlyElement(testPlan.getRoots()))).isEmpty();
Map<TestIdentifier, TestExecutionResult> results = execute(request);
//
assertThat(results.keySet().stream().map(TestIdentifier::getDisplayName)).containsExactly("JUnit Vintage");
}
Aggregations