Search in sources :

Example 1 with TestDescriptorStub

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

the class DefaultLauncherTests method prunesTestDescriptorsAfterApplyingPostDiscoveryFilters.

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

        @Override
        public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
            super.discover(discoveryRequest, uniqueId);
            var engineDescriptor = new TestDescriptorStub(uniqueId, uniqueId.toString());
            var 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;
        }
    };
    var launcher = createLauncher(engine);
    var testPlan = launcher.discover(request().filters((PostDiscoveryFilter) testDescriptor -> FilterResult.includedIf(testDescriptor.isContainer())).build());
    assertThat(testPlan.getRoots()).hasSize(1);
    var engineIdentifier = getOnlyElement(testPlan.getRoots());
    assertThat(testPlan.getChildren(engineIdentifier)).isEmpty();
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestPlan(org.junit.platform.launcher.TestPlan) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LauncherDiscoveryListener(org.junit.platform.launcher.LauncherDiscoveryListener) TestEngineSpy(org.junit.platform.fakes.TestEngineSpy) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) PostDiscoveryFilter(org.junit.platform.launcher.PostDiscoveryFilter) JUnitException(org.junit.platform.commons.JUnitException) LogRecord(java.util.logging.LogRecord) Test(org.junit.jupiter.api.Test) LogRecordListener(org.junit.platform.commons.logging.LogRecordListener) 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) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Mockito.inOrder(org.mockito.Mockito.inOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestDescriptor(org.junit.platform.engine.TestDescriptor) Mockito.mock(org.mockito.Mockito.mock) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.DEFAULT_DISCOVERY_LISTENER_CONFIGURATION_PROPERTY_NAME) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) EngineFilter.excludeEngines(org.junit.platform.launcher.EngineFilter.excludeEngines) FilterResult(org.junit.platform.engine.FilterResult) TestEngine(org.junit.platform.engine.TestEngine) TestExecutionResult(org.junit.platform.engine.TestExecutionResult) Level(java.util.logging.Level) EngineDiscoveryResult(org.junit.platform.launcher.EngineDiscoveryResult) TestExecutionResult.successful(org.junit.platform.engine.TestExecutionResult.successful) 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) TrackLogRecords(org.junit.jupiter.api.fixtures.TrackLogRecords) ValueSource(org.junit.jupiter.params.provider.ValueSource) EngineFilter.includeEngines(org.junit.platform.launcher.EngineFilter.includeEngines) CollectionUtils.getOnlyElement(org.junit.platform.commons.util.CollectionUtils.getOnlyElement) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) UniqueId(org.junit.platform.engine.UniqueId) Mockito.verify(org.mockito.Mockito.verify) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ExceptionUtils(org.junit.platform.commons.util.ExceptionUtils) ExecutionRequest(org.junit.platform.engine.ExecutionRequest) DiscoverySelectors.selectPackage(org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) TestEngineSpy(org.junit.platform.fakes.TestEngineSpy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestDescriptorStub

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

the class XmlReportWriterTests method omitsMessageAttributeForFailedTestWithThrowableWithoutMessage.

@Test
void omitsMessageAttributeForFailedTestWithThrowableWithoutMessage() throws Exception {
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "failedTest"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(new NullPointerException()));
    var testsuite = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(testsuite.document());
    var error = testsuite.find("error");
    assertThat(error.attr("type")).isEqualTo("java.lang.NullPointerException");
    assertThat(error.attr("message")).isNull();
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TestDescriptorStub

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

the class XmlReportDataTests method resultsOfTestIdentifierWithoutAnyReportedEventsAreEmpty.

@Test
void resultsOfTestIdentifierWithoutAnyReportedEventsAreEmpty() {
    var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    var results = reportData.getResults(testPlan.getTestIdentifier("[child:test]"));
    assertThat(results).isEmpty();
}
Also used : EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 4 with TestDescriptorStub

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

the class XmlReportDataTests method resultsOfTestIdentifierWithoutReportedEventsContainsOnlySuccessOfAncestor.

@Test
void resultsOfTestIdentifierWithoutReportedEventsContainsOnlySuccessOfAncestor() {
    var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), successful());
    var results = reportData.getResults(testPlan.getTestIdentifier("[child:test]"));
    assertThat(results).containsExactly(successful());
}
Also used : EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 5 with TestDescriptorStub

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

the class SummaryGenerationTests method reportingConcurrentlyFinishedTests.

@RepeatedTest(10)
void reportingConcurrentlyFinishedTests() throws Exception {
    var numThreads = 250;
    var testIdentifier = TestIdentifier.from(new TestDescriptorStub(UniqueId.root("root", "2"), "failingTest") {

        @Override
        public Optional<TestSource> getSource() {
            return Optional.of(ClassSource.from(Object.class));
        }
    });
    var result = TestExecutionResult.failed(new RuntimeException());
    listener.testPlanExecutionStarted(testPlan);
    executeConcurrently(numThreads, () -> {
        listener.executionStarted(testIdentifier);
        listener.executionFinished(testIdentifier, result);
    });
    listener.testPlanExecutionFinished(testPlan);
    assertThat(listener.getSummary().getFailures()).hasSize(numThreads);
}
Also used : Optional(java.util.Optional) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Aggregations

TestDescriptorStub (org.junit.platform.fakes.TestDescriptorStub)22 Test (org.junit.jupiter.api.Test)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)6 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 TestEngineSpy (org.junit.platform.fakes.TestEngineSpy)3 StringWriter (java.io.StringWriter)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestEngine (org.junit.platform.engine.TestEngine)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)2 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1