use of org.junit.platform.engine.TestSource in project junit5 by junit-team.
the class SummaryGenerationTests method canGetListOfFailures.
@Test
void canGetListOfFailures() {
RuntimeException failedException = new RuntimeException("Pow!");
TestDescriptorStub testDescriptor = new TestDescriptorStub(UniqueId.root("root", "1"), "failingTest") {
@Override
public Optional<TestSource> getSource() {
return Optional.of(ClassSource.from(Object.class));
}
};
TestIdentifier failingTest = TestIdentifier.from(testDescriptor);
listener.testPlanExecutionStarted(testPlan);
listener.executionStarted(failingTest);
listener.executionFinished(failingTest, TestExecutionResult.failed(failedException));
listener.testPlanExecutionFinished(testPlan);
final List<TestExecutionSummary.Failure> failures = listener.getSummary().getFailures();
assertThat(failures).hasSize(1);
assertThat(failures.get(0).getException()).isEqualTo(failedException);
assertThat(failures.get(0).getTestIdentifier()).isEqualTo(failingTest);
}
use of org.junit.platform.engine.TestSource in project junit5 by junit-team.
the class TestIdentifier method from.
/**
* Factory for creating a new {@link TestIdentifier} from a {@link TestDescriptor}.
*/
@API(status = INTERNAL, since = "1.0")
public static TestIdentifier from(TestDescriptor testDescriptor) {
Preconditions.notNull(testDescriptor, "TestDescriptor must not be null");
String uniqueId = testDescriptor.getUniqueId().toString();
String displayName = testDescriptor.getDisplayName();
TestSource source = testDescriptor.getSource().orElse(null);
Set<TestTag> tags = testDescriptor.getTags();
Type type = testDescriptor.getType();
String parentId = testDescriptor.getParent().map(parentDescriptor -> parentDescriptor.getUniqueId().toString()).orElse(null);
String legacyReportingName = testDescriptor.getLegacyReportingName();
return new TestIdentifier(uniqueId, displayName, source, tags, type, parentId, legacyReportingName);
}
use of org.junit.platform.engine.TestSource in project intellij-community by JetBrains.
the class JUnit5TestExecutionListener method getLocationHintValue.
static String getLocationHintValue(TestSource testSource, boolean isTest) {
if (testSource instanceof CompositeTestSource) {
CompositeTestSource compositeTestSource = ((CompositeTestSource) testSource);
for (TestSource sourceFromComposite : compositeTestSource.getSources()) {
String locationHintValue = getLocationHintValue(sourceFromComposite, isTest);
if (!NO_LOCATION_HINT_VALUE.equals(locationHintValue)) {
return locationHintValue;
}
}
return NO_LOCATION_HINT_VALUE;
}
if (testSource instanceof FileSource) {
FileSource fileSource = (FileSource) testSource;
File file = fileSource.getFile();
String line = fileSource.getPosition().map(position -> ":" + position.getLine()).orElse("");
return "file://" + file.getAbsolutePath() + line;
}
if (testSource instanceof MethodSource) {
MethodSource methodSource = (MethodSource) testSource;
return javaLocation(methodSource.getClassName(), methodSource.getMethodName(), isTest);
}
if (testSource instanceof ClassSource) {
String className = ((ClassSource) testSource).getClassName();
return javaLocation(className, null, isTest);
}
return NO_LOCATION_HINT_VALUE;
}
use of org.junit.platform.engine.TestSource in project ant by apache.
the class AbstractJUnitResultFormatter method isTestClass.
static Optional<ClassSource> isTestClass(final TestIdentifier testIdentifier) {
if (testIdentifier == null) {
return Optional.empty();
}
final Optional<TestSource> source = testIdentifier.getSource();
if (!source.isPresent()) {
return Optional.empty();
}
final TestSource testSource = source.get();
if (testSource instanceof ClassSource) {
return Optional.of((ClassSource) testSource);
}
return Optional.empty();
}
use of org.junit.platform.engine.TestSource in project junit5 by junit-team.
the class TestFactoryTestDescriptor method invokeTestMethod.
// --- Node ----------------------------------------------------------------
@Override
protected void invokeTestMethod(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) {
ExtensionContext extensionContext = context.getExtensionContext();
context.getThrowableCollector().execute(() -> {
Object instance = extensionContext.getRequiredTestInstance();
Object testFactoryMethodResult = executableInvoker.invoke(getTestMethod(), instance, extensionContext, context.getExtensionRegistry());
TestSource source = getSource().orElseThrow(() -> new JUnitException("Illegal state: TestSource must be present"));
try (Stream<DynamicNode> dynamicNodeStream = toDynamicNodeStream(testFactoryMethodResult)) {
int index = 1;
Iterator<DynamicNode> iterator = dynamicNodeStream.iterator();
while (iterator.hasNext()) {
DynamicNode dynamicNode = iterator.next();
Optional<JupiterTestDescriptor> descriptor = createDynamicDescriptor(this, dynamicNode, index++, source, getDynamicDescendantFilter());
descriptor.ifPresent(dynamicTestExecutor::execute);
}
} catch (ClassCastException ex) {
throw invalidReturnTypeException(ex);
}
});
}
Aggregations