Search in sources :

Example 6 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class TestClassWithTemplate method resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory.

@Test
@TrackLogRecords
void resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory(LogRecordListener listener) {
    Class<?> clazz = MyTestClass.class;
    UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
    UniqueId dynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
    UniqueId differentDynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#2");
    resolver.resolveSelectors(request().selectors(selectUniqueId(dynamicTestUid)).build(), 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(dynamicTestUid)).isTrue();
    assertThat(dynamicDescendantFilter.test(differentDynamicTestUid)).isFalse();
    assertThat(listener.stream(JavaElementsResolver.class)).isEmpty();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) 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) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 7 with TrackLogRecords

use of org.junit.jupiter.engine.TrackLogRecords in project junit5 by junit-team.

the class TestClassWithTemplate method resolvingDynamicContainerByUniqueIdResolvesUpToParentTestFactory.

@Test
@TrackLogRecords
void resolvingDynamicContainerByUniqueIdResolvesUpToParentTestFactory(LogRecordListener listener) {
    Class<?> clazz = MyTestClass.class;
    UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
    UniqueId dynamicContainerUid = factoryUid.append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#1");
    UniqueId differentDynamicContainerUid = factoryUid.append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#2");
    UniqueId dynamicTestUid = dynamicContainerUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
    UniqueId differentDynamicTestUid = dynamicContainerUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#2");
    resolver.resolveSelectors(request().selectors(selectUniqueId(dynamicTestUid)).build(), 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(dynamicTestUid)).isTrue();
    assertThat(dynamicDescendantFilter.test(differentDynamicContainerUid)).isFalse();
    assertThat(dynamicDescendantFilter.test(differentDynamicTestUid)).isFalse();
    assertThat(listener.stream(JavaElementsResolver.class)).isEmpty();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) 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) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Aggregations

Test (org.junit.jupiter.api.Test)7 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)7 DynamicTest (org.junit.jupiter.api.DynamicTest)5 UniqueId (org.junit.platform.engine.UniqueId)5 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)5 LogRecord (java.util.logging.LogRecord)4 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Level (java.util.logging.Level)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)2 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)2 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)2 LogRecordListener (org.junit.platform.commons.logging.LogRecordListener)2 CollectionUtils.getOnlyElement (org.junit.platform.commons.util.CollectionUtils.getOnlyElement)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 FilterResult.excluded (org.junit.platform.engine.FilterResult.excluded)2 FilterResult.includedIf (org.junit.platform.engine.FilterResult.includedIf)2 TestDescriptor (org.junit.platform.engine.TestDescriptor)2 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)2