Search in sources :

Example 11 with DemoHierarchicalTestEngine

use of org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method measuresTimesInSeconds.

@Test
void measuresTimesInSeconds(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("firstTest", () -> {
    });
    engine.addTest("secondTest", () -> {
    });
    executeTests(engine, tempDirectory, new IncrementingClock(0, Duration.ofMillis(333)));
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    // start        end
    // ----------- ---------- -----------
    // engine          0 (1)    1,665 (6)
    // firstTest     333 (2)      666 (3)
    // secondTest    999 (4)    1,332 (5)
    assertThat(content).containsSubsequence("<testsuite", "time=\"1.665\"", "<testcase name=\"firstTest\" classname=\"dummy\" time=\"0.333\"", "<testcase name=\"secondTest\" classname=\"dummy\" time=\"0.333\"");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 12 with DemoHierarchicalTestEngine

use of org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesFileForSingleFailingTest.

@Test
void writesFileForSingleFailingTest(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("failingTest", () -> fail("expected to <b>fail</b>"));
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"0\" failures=\"1\" errors=\"0\"", "<testcase name=\"failingTest\"", "<failure message=\"expected to &lt;b&gt;fail&lt;/b&gt;\" type=\"" + AssertionFailedError.class.getName() + "\">", "AssertionFailedError: expected to <b>fail</b>", "\tat", "</failure>", "</testcase>", "</testsuite>").doesNotContain("<skipped").doesNotContain("<error");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 13 with DemoHierarchicalTestEngine

use of org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesFileForSingleSkippedTest.

@Test
void writesFileForSingleSkippedTest(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    DemoHierarchicalTestDescriptor testDescriptor = engine.addTest("skippedTest", () -> fail("never called"));
    testDescriptor.markSkipped("should be skipped");
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"1\" failures=\"0\" errors=\"0\"", "<testcase name=\"skippedTest\"", "<skipped>", "should be skipped", "</skipped>", "</testcase>", "</testsuite>").doesNotContain("<failure").doesNotContain("<error");
// @formatter:on
}
Also used : DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 14 with DemoHierarchicalTestEngine

use of org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method testWithImmeasurableTimeIsOutputCorrectly.

@Test
void testWithImmeasurableTimeIsOutputCorrectly(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("test", () -> {
    });
    executeTests(engine, tempDirectory, Clock.fixed(Instant.EPOCH, ZoneId.systemDefault()));
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite", "<testcase name=\"test\" classname=\"dummy\" time=\"0\"");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 15 with DemoHierarchicalTestEngine

use of org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesFileForSkippedContainer.

@Test
void writesFileForSkippedContainer(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("test", () -> fail("never called"));
    engine.getEngineDescriptor().markSkipped("should be skipped");
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"1\" failures=\"0\" errors=\"0\"", "<testcase name=\"test\"", "<skipped>", "parent was skipped: should be skipped", "</skipped>", "</testcase>", "</testsuite>");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)24 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)24 TestPlan (org.junit.platform.launcher.TestPlan)9 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)8 TestDescriptor (org.junit.platform.engine.TestDescriptor)6 TestIdentifier (org.junit.platform.launcher.TestIdentifier)4 PreconditionViolationException (org.junit.platform.commons.util.PreconditionViolationException)3 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 JUnitException (org.junit.platform.commons.JUnitException)1 PostDiscoveryFilter (org.junit.platform.launcher.PostDiscoveryFilter)1 PostDiscoveryFilterStub (org.junit.platform.launcher.PostDiscoveryFilterStub)1