use of org.junit.platform.engine.TestSource in project junit5 by junit-team.
the class CompositeTestSourceTests method createCompositeTestSourceFromClassAndFileSources.
@Test
void createCompositeTestSourceFromClassAndFileSources() {
FileSource fileSource = FileSource.from(new File("example.test"));
ClassSource classSource = ClassSource.from(getClass());
List<TestSource> sources = new ArrayList<>(Arrays.asList(fileSource, classSource));
CompositeTestSource compositeTestSource = CompositeTestSource.from(sources);
assertThat(compositeTestSource.getSources().size()).isEqualTo(2);
assertThat(compositeTestSource.getSources()).contains(fileSource, classSource);
// Ensure the supplied sources list was defensively copied.
sources.remove(1);
assertThat(compositeTestSource.getSources().size()).isEqualTo(2);
// Ensure the returned sources list is immutable.
assertThrows(UnsupportedOperationException.class, () -> compositeTestSource.getSources().add(fileSource));
}
use of org.junit.platform.engine.TestSource in project junit5 by junit-team.
the class SummaryGenerationTests method reportingCorrectFailures.
@Test
void reportingCorrectFailures() {
RuntimeException failedException = new RuntimeException("failed");
TestDescriptorStub testDescriptor = new TestDescriptorStub(UniqueId.root("root", "2"), "failingTest") {
@Override
public Optional<TestSource> getSource() {
return Optional.of(ClassSource.from(Object.class));
}
};
TestIdentifier failed = TestIdentifier.from(testDescriptor);
TestIdentifier aborted = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("root", "3"), "abortedTest"));
listener.testPlanExecutionStarted(testPlan);
listener.executionStarted(failed);
listener.executionFinished(failed, TestExecutionResult.failed(failedException));
listener.executionStarted(aborted);
listener.executionFinished(aborted, TestExecutionResult.aborted(new RuntimeException("aborted")));
listener.testPlanExecutionFinished(testPlan);
// An aborted test is not a failure
assertEquals(1, listener.getSummary().getTestsFailedCount());
String failuresString = failuresAsString();
assertAll(//
"failures", //
() -> assertTrue(failuresString.contains("Failures (1)"), "test failures"), //
() -> assertTrue(failuresString.contains(Object.class.getName()), "source"), //
() -> assertTrue(failuresString.contains("failingTest"), "display name"), //
() -> assertTrue(failuresString.contains("=> " + failedException), "exception"));
}
Aggregations