Search in sources :

Example 16 with TestDescriptorStub

use of org.junit.platform.engine.test.TestDescriptorStub in project junit5 by junit-team.

the class SummaryGenerationTests method createTestIdentifier.

private TestIdentifier createTestIdentifier(String uniqueId) {
    TestIdentifier identifier = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("test", uniqueId), uniqueId));
    testPlan.add(identifier);
    return identifier;
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub)

Example 17 with TestDescriptorStub

use of org.junit.platform.engine.test.TestDescriptorStub 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)

Example 18 with TestDescriptorStub

use of org.junit.platform.engine.test.TestDescriptorStub in project junit5 by junit-team.

the class SummaryGenerationTests method createContainerIdentifier.

private TestIdentifier createContainerIdentifier(String uniqueId) {
    TestIdentifier identifier = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("container", uniqueId), uniqueId) {

        @Override
        public Type getType() {
            return Type.CONTAINER;
        }
    });
    testPlan.add(identifier);
    return identifier;
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub)

Aggregations

TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)18 Test (org.junit.jupiter.api.Test)16 TestPlan (org.junit.platform.launcher.TestPlan)11 UniqueId (org.junit.platform.engine.UniqueId)7 TestIdentifier (org.junit.platform.launcher.TestIdentifier)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)3 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestSource (org.junit.platform.engine.TestSource)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)2 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1