Search in sources :

Example 6 with TestSource

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));
}
Also used : TestSource(org.junit.platform.engine.TestSource) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 7 with TestSource

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"));
}
Also used : TestSource(org.junit.platform.engine.TestSource) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Aggregations

TestSource (org.junit.platform.engine.TestSource)7 Test (org.junit.jupiter.api.Test)3 TestIdentifier (org.junit.platform.launcher.TestIdentifier)3 File (java.io.File)2 Set (java.util.Set)2 ClassSource (org.junit.platform.engine.support.descriptor.ClassSource)2 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)2 ExpectedPatterns (com.intellij.junit4.ExpectedPatterns)1 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)1 ComparisonFailureData (com.intellij.rt.execution.junit.ComparisonFailureData)1 MapSerializerUtil (com.intellij.rt.execution.junit.MapSerializerUtil)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 Serializable (java.io.Serializable)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Collections.unmodifiableSet (java.util.Collections.unmodifiableSet)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1