Search in sources :

Example 61 with UniqueId

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

the class XmlReportWriterTests method writesEmptySkippedElementForSkippedTestWithoutReason.

@Test
void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null);
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"skippedTest\"", "<skipped/>", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 62 with UniqueId

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

the class XmlReportWriterTests method omitsMessageAttributeForFailedTestWithThrowableWithoutMessage.

@Test
void omitsMessageAttributeForFailedTestWithThrowableWithoutMessage() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "failedTest"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(new NullPointerException()));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"failedTest\"", "<error type=\"java.lang.NullPointerException\">", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 63 with UniqueId

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

the class RunListenerAdapter method registerDynamicTestDescriptor.

private VintageTestDescriptor registerDynamicTestDescriptor(Description description) {
    // workaround for dynamic children as used by Spock's Runner
    TestDescriptor parent = findParent(description);
    UniqueId uniqueId = parent.getUniqueId().append(SEGMENT_TYPE_DYNAMIC, uniqueIdExtractor.apply(description));
    VintageTestDescriptor dynamicDescriptor = new VintageTestDescriptor(uniqueId, description);
    parent.addChild(dynamicDescriptor);
    testRun.registerDynamicTest(dynamicDescriptor);
    dynamicTestRegistered(dynamicDescriptor);
    return dynamicDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 64 with UniqueId

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

the class TestClassWithTemplate method resolvingDynamicTestByUniqueIdAndTestFactoryByMethodSelectorResolvesTestFactory.

@Test
void resolvingDynamicTestByUniqueIdAndTestFactoryByMethodSelectorResolvesTestFactory() {
    Class<?> clazz = MyTestClass.class;
    UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
    UniqueId dynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
    LauncherDiscoveryRequest request = // 
    request().selectors(selectUniqueId(dynamicTestUid), // 
    selectMethod(clazz, "dynamicTest")).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertThat(engineDescriptor.getDescendants()).hasSize(2);
    assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
    TestDescriptor testClassDescriptor = getOnlyElement(engineDescriptor.getChildren());
    TestDescriptor testFactoryDescriptor = getOnlyElement(testClassDescriptor.getChildren());
    DynamicDescendantFilter dynamicDescendantFilter = getDynamicDescendantFilter(testFactoryDescriptor);
    assertThat(dynamicDescendantFilter.test(UniqueId.root("foo", "bar"))).isTrue();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) DynamicDescendantFilter(org.junit.jupiter.engine.descriptor.DynamicDescendantFilter) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) JupiterTestDescriptor(org.junit.jupiter.engine.descriptor.JupiterTestDescriptor) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 65 with UniqueId

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

the class TestClassWithTemplate method testFactoryMethodResolutionByUniqueId.

@Test
void testFactoryMethodResolutionByUniqueId() {
    Class<?> clazz = MyTestClass.class;
    UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
    resolver.resolveSelectors(request().selectors(selectUniqueId(factoryUid)).build(), engineDescriptor);
    assertThat(engineDescriptor.getDescendants()).hasSize(2);
    assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)131 Test (org.junit.jupiter.api.Test)95 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)83 DynamicTest (org.junit.jupiter.api.DynamicTest)64 TestDescriptor (org.junit.platform.engine.TestDescriptor)29 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)25 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)15 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)14 List (java.util.List)9 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)8 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)8 TestPlan (org.junit.platform.launcher.TestPlan)8 JUnitException (org.junit.platform.commons.JUnitException)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)6 TestEngine (org.junit.platform.engine.TestEngine)6 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5