Search in sources :

Example 41 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 42 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 43 with UniqueId

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

the class TestRunTests method returnsEmptyOptionalForUnknownDescriptions.

@Test
void returnsEmptyOptionalForUnknownDescriptions() throws Exception {
    Class<?> testClass = PlainJUnit4TestCaseWithSingleTestWhichFails.class;
    UniqueId runnerId = engineId().append(SEGMENT_TYPE_RUNNER, testClass.getName());
    RunnerTestDescriptor runnerTestDescriptor = new RunnerTestDescriptor(runnerId, testClass, new BlockJUnit4ClassRunner(testClass));
    Description unknownDescription = createTestDescription(testClass, "dynamicTest");
    TestRun testRun = new TestRun(runnerTestDescriptor);
    Optional<VintageTestDescriptor> testDescriptor = testRun.lookupTestDescriptor(unknownDescription);
    assertThat(testDescriptor).isEmpty();
}
Also used : PlainJUnit4TestCaseWithSingleTestWhichFails(org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichFails) UniqueId(org.junit.platform.engine.UniqueId) RunnerTestDescriptor(org.junit.vintage.engine.descriptor.RunnerTestDescriptor) Description.createTestDescription(org.junit.runner.Description.createTestDescription) Description(org.junit.runner.Description) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) VintageTestDescriptor(org.junit.vintage.engine.descriptor.VintageTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 44 with UniqueId

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

the class TestTemplateTestDescriptorTests method inheritsTagsFromParent.

@Test
void inheritsTagsFromParent() throws Exception {
    UniqueId rootUniqueId = UniqueId.root("segment", "template");
    UniqueId parentUniqueId = rootUniqueId.append("class", "myClass");
    AbstractTestDescriptor parent = containerTestDescriptorWithTags(parentUniqueId, singleton(TestTag.create("foo")));
    TestTemplateTestDescriptor testDescriptor = new TestTemplateTestDescriptor(parentUniqueId.append("tmp", "testTemplate()"), MyTestCase.class, MyTestCase.class.getDeclaredMethod("testTemplate"));
    parent.addChild(testDescriptor);
    assertThat(testDescriptor.getTags()).containsExactlyInAnyOrder(TestTag.create("foo"), TestTag.create("bar"), TestTag.create("baz"));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) AbstractTestDescriptor(org.junit.platform.engine.support.descriptor.AbstractTestDescriptor) Test(org.junit.jupiter.api.Test)

Example 45 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)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)78 Test (org.junit.jupiter.api.Test)59 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)44 DynamicTest (org.junit.jupiter.api.DynamicTest)32 TestDescriptor (org.junit.platform.engine.TestDescriptor)19 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)13 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)12 TestPlan (org.junit.platform.launcher.TestPlan)10 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)8 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)7 List (java.util.List)5 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)4 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)4 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)4 ExecutionEventRecorder (org.junit.platform.engine.test.event.ExecutionEventRecorder)4 Optional (java.util.Optional)3