Search in sources :

Example 1 with TestDescriptorStub

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

the class TestIdentifierTests method inheritsIdAndNamesFromDescriptor.

@Test
void inheritsIdAndNamesFromDescriptor() {
    TestDescriptor testDescriptor = new TestDescriptorStub(UniqueId.root("aType", "uniqueId"), "displayName");
    TestIdentifier testIdentifier = TestIdentifier.from(testDescriptor);
    assertEquals("[aType:uniqueId]", testIdentifier.getUniqueId());
    assertEquals("displayName", testIdentifier.getDisplayName());
}
Also used : TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with TestDescriptorStub

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

the class TestIdentifierTests method inheritsTypeFromDescriptor.

@Test
void inheritsTypeFromDescriptor() {
    TestDescriptor descriptor = new TestDescriptorStub(UniqueId.root("aType", "uniqueId"), "displayName");
    TestIdentifier identifier = TestIdentifier.from(descriptor);
    assertEquals(TestDescriptor.Type.TEST, identifier.getType());
    assertTrue(identifier.isTest());
    assertFalse(identifier.isContainer());
    descriptor.addChild(new TestDescriptorStub(UniqueId.root("aChild", "uniqueId"), "displayName"));
    identifier = TestIdentifier.from(descriptor);
    assertEquals(TestDescriptor.Type.CONTAINER, identifier.getType());
    assertFalse(identifier.isTest());
    assertTrue(identifier.isContainer());
}
Also used : TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with TestDescriptorStub

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

the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.

@Test
void prunesTestDescriptorsAfterApplyingPostDiscoveryFilters() {
    TestEngineSpy engine = new TestEngineSpy() {

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            TestDescriptorStub engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            TestDescriptorStub containerDescriptor = new TestDescriptorStub(uniqueId.append("container", "a"), "container") {

                @Override
                public Type getType() {
                    return Type.CONTAINER;
                }
            };
            containerDescriptor.addChild(new TestDescriptorStub(containerDescriptor.getUniqueId().append("test", "b"), "test"));
            engineDescriptor.addChild(containerDescriptor);
            return engineDescriptor;
        }
    };
    DefaultLauncher launcher = createLauncher(engine);
    TestPlan testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    TestIdentifier engineIdentifier = getOnlyElement(testPlan.getRoots());
    assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestPlan(org.junit.platform.launcher.TestPlan) EngineFilter.excludeEngines(org.junit.platform.launcher.EngineFilter.excludeEngines) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) TestExecutionResult.successful(org.junit.platform.engine.TestExecutionResult.successful) EngineExecutionListener(org.junit.platform.engine.EngineExecutionListener) ArgumentCaptor(org.mockito.ArgumentCaptor) LauncherFactoryForTestingPurposesOnly.createLauncher(org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly.createLauncher) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) InOrder(org.mockito.InOrder) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) JUnitException(org.junit.platform.commons.JUnitException) TestEngineStub(org.junit.platform.engine.test.TestEngineStub) UniqueId(org.junit.platform.engine.UniqueId) Test(org.junit.jupiter.api.Test) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) TestIdentifier(org.junit.platform.launcher.TestIdentifier) PostDiscoveryFilterStub(org.junit.platform.launcher.PostDiscoveryFilterStub) SummaryGeneratingListener(org.junit.platform.launcher.listeners.SummaryGeneratingListener) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) DemoHierarchicalTestDescriptor(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) TestDescriptor(org.junit.platform.engine.TestDescriptor) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) UniqueId(org.junit.platform.engine.UniqueId) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 4 with TestDescriptorStub

use of org.junit.platform.engine.test.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";
        }
    };
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "some fancy name") {

        @Override
        public String getLegacyReportingName() {
            return "failedTest";
        }
    });
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(null));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"failedTest\" classname=\"myEngine\"", "<error/>", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 5 with TestDescriptorStub

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

the class XmlReportWriterTests method writesReportEntry.

@Test
void writesReportEntry() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    TestDescriptorStub testDescriptor = new TestDescriptorStub(uniqueId, "successfulTest");
    engineDescriptor.addChild(testDescriptor);
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.addReportEntry(TestIdentifier.from(testDescriptor), ReportEntry.from("myKey", "myValue"));
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), successful());
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<system-out>", "Report Entry #1 (timestamp: ", "- myKey: myValue", "</system-out>");
// @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)

Aggregations

TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)18 Test (org.junit.jupiter.api.Test)16 TestPlan (org.junit.platform.launcher.TestPlan)11 UniqueId (org.junit.platform.engine.UniqueId)7 TestIdentifier (org.junit.platform.launcher.TestIdentifier)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)3 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 EngineExecutionListener (org.junit.platform.engine.EngineExecutionListener)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestSource (org.junit.platform.engine.TestSource)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 DemoHierarchicalTestDescriptor (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestDescriptor)2 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)2 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1