Search in sources :

Example 16 with TestDescriptorStub

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

the class XmlReportWriterTests method writesEmptyErrorElementForFailedTestWithoutCause.

@Test
void writesEmptyErrorElementForFailedTestWithoutCause() throws Exception {
    engineDescriptor = new EngineDescriptor(UniqueId.forEngine("myEngineId"), "Fancy Engine") {

        @Override
        public String getLegacyReportingName() {
            return "myEngine";
        }
    };
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "some fancy name") {

        @Override
        public String getLegacyReportingName() {
            return "failedTest";
        }
    });
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(null));
    var testsuite = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(testsuite.document());
    var testcase = testsuite.child("testcase");
    assertThat(testcase.attr("name")).isEqualTo("failedTest");
    assertThat(testcase.attr("classname")).isEqualTo("myEngine");
    var error = testcase.child("error");
    assertThat(error.size()).isEqualTo(1);
    assertThat(error.children()).isEmpty();
}
Also used : EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with TestDescriptorStub

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

the class LegacyXmlReportGeneratingListenerTests method writesReportEntriesToSystemOutElement.

@Test
void writesReportEntriesToSystemOutElement() throws Exception {
    var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), mock(ConfigurationParameters.class));
    var out = new StringWriter();
    var listener = new LegacyXmlReportGeneratingListener(tempDirectory, new PrintWriter(out));
    listener.testPlanExecutionStarted(testPlan);
    var testIdentifier = testPlan.getTestIdentifier("[child:test]");
    listener.executionStarted(testIdentifier);
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from("foo", "bar"));
    Map<String, String> map = new LinkedHashMap<>();
    map.put("bar", "baz");
    map.put("qux", "foo");
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from(map));
    listener.executionFinished(testIdentifier, successful());
    listener.executionFinished(testPlan.getTestIdentifier("[engine:engine]"), successful());
    var testsuite = readValidXmlFile(tempDirectory.resolve("TEST-engine.xml"));
    // 
    assertThat(String.join("\n", testsuite.child("testcase").children("system-out").texts())).containsSubsequence("Report Entry #1 (timestamp: " + Year.now(), "- foo: bar\n", "Report Entry #2 (timestamp: " + Year.now(), "- bar: baz\n", "- qux: foo\n");
}
Also used : StringWriter(java.io.StringWriter) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) PrintWriter(java.io.PrintWriter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 18 with TestDescriptorStub

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

the class XmlReportDataTests method resultsOfTestIdentifierWithoutReportedEventsContainsOnlyFailureOfAncestor.

@Test
void resultsOfTestIdentifierWithoutReportedEventsContainsOnlyFailureOfAncestor() {
    var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    var failureOfAncestor = failed(new RuntimeException("failed!"));
    reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), failureOfAncestor);
    var results = reportData.getResults(testPlan.getTestIdentifier("[child:test]"));
    assertThat(results).containsExactly(failureOfAncestor);
}
Also used : EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 19 with TestDescriptorStub

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

the class SummaryGenerationTests method reportingCorrectFailures.

@Test
void reportingCorrectFailures() {
    var iaeCausedBy = new IllegalArgumentException("Illegal Argument Exception");
    var failedException = new RuntimeException("Runtime Exception", iaeCausedBy);
    var npeSuppressed = new NullPointerException("Null Pointer Exception");
    failedException.addSuppressed(npeSuppressed);
    var testDescriptor = new TestDescriptorStub(UniqueId.root("root", "2"), "failingTest") {

        @Override
        public Optional<TestSource> getSource() {
            return Optional.of(ClassSource.from(Object.class));
        }
    };
    var failed = TestIdentifier.from(testDescriptor);
    var 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());
    var 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), "main exception"), // 
    () -> assertTrue(failuresString.contains("Caused by: " + iaeCausedBy), "Caused by exception"), // 
    () -> assertTrue(failuresString.contains("Suppressed: " + npeSuppressed), "Suppressed exception"));
}
Also used : TestSource(org.junit.platform.engine.TestSource) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 20 with TestDescriptorStub

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

the class SummaryGenerationTests method createContainerIdentifier.

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

        @Override
        public Type getType() {
            return Type.CONTAINER;
        }
    });
    testPlan.addInternal(identifier);
    return identifier;
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub)

Aggregations

TestDescriptorStub (org.junit.platform.fakes.TestDescriptorStub)22 Test (org.junit.jupiter.api.Test)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)6 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 TestEngineSpy (org.junit.platform.fakes.TestEngineSpy)3 StringWriter (java.io.StringWriter)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestEngine (org.junit.platform.engine.TestEngine)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)2 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1