Search in sources :

Example 6 with DemoHierarchicalTestEngine

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

the class DefaultLauncherTests method launcherAppliesPostDiscoveryFilters.

@Test
void launcherAppliesPostDiscoveryFilters() {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("myEngine");
    DemoHierarchicalTestDescriptor test1 = engine.addTest("test1", noOp);
    engine.addTest("test2", noOp);
    DefaultLauncher launcher = createLauncher(engine);
    PostDiscoveryFilter includeWithUniqueIdContainsTest = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("test")), () -> "filter1");
    PostDiscoveryFilter includeWithUniqueIdContains1 = new PostDiscoveryFilterStub(descriptor -> FilterResult.includedIf(descriptor.getUniqueId().toString().contains("1")), () -> "filter2");
    TestPlan testPlan = // 
    launcher.discover(// 
    request().selectors(// 
    selectPackage("any")).filters(includeWithUniqueIdContainsTest, // 
    includeWithUniqueIdContains1).build());
    assertThat(testPlan.getChildren(UniqueId.forEngine("myEngine").toString())).hasSize(1);
    assertThat(testPlan.getTestIdentifier(test1.getUniqueId().toString())).isNotNull();
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) Test(org.junit.jupiter.api.Test)

Example 7 with DemoHierarchicalTestEngine

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

the class DefaultLauncherTests method discoverEmptyTestPlanWithEngineWithoutAnyTests.

@Test
void discoverEmptyTestPlanWithEngineWithoutAnyTests() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine());
    TestPlan testPlan = launcher.discover(request().build());
    assertThat(testPlan.getRoots()).hasSize(1);
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 8 with DemoHierarchicalTestEngine

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

the class DefaultLauncherTests method registerTestExecutionListenersWithArrayContainingNullElements.

@Test
void registerTestExecutionListenersWithArrayContainingNullElements() {
    DefaultLauncher launcher = createLauncher(new DemoHierarchicalTestEngine("dummy id"));
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> launcher.registerTestExecutionListeners(new TestExecutionListener[] { null }));
    assertThat(exception).hasMessageContaining("individual listeners must not be null");
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Example 9 with DemoHierarchicalTestEngine

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

the class XmlReportsWritingListenerTests method writesHostNameAndTimestamp.

@Test
void writesHostNameAndTimestamp(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("test", () -> {
    });
    LocalDateTime now = LocalDateTime.parse("2016-01-28T14:02:59.123");
    ZoneId zone = ZoneId.systemDefault();
    executeTests(engine, tempDirectory, Clock.fixed(ZonedDateTime.of(now, zone).toInstant(), zone));
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite", "hostname=\"" + InetAddress.getLocalHost().getHostName() + "\"", "timestamp=\"2016-01-28T14:02:59\"", "<testcase", "</testsuite>");
// @formatter:on
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) Test(org.junit.jupiter.api.Test)

Example 10 with DemoHierarchicalTestEngine

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

the class XmlReportsWritingListenerTests method writesFileForSingleErroneousTest.

@Test
void writesFileForSingleErroneousTest(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("failingTest", () -> {
        throw new RuntimeException("error occurred");
    });
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"0\" failures=\"0\" errors=\"1\"", "<testcase name=\"failingTest\"", "<error message=\"error occurred\" type=\"java.lang.RuntimeException\">", "RuntimeException: error occurred", "\tat ", "</error>", "</testcase>", "</testsuite>").doesNotContain("<skipped").doesNotContain("<failure");
// @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