Search in sources :

Example 16 with UniqueId

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

the class TestClassWithTemplate method singleClassResolution.

@Test
void singleClassResolution() {
    ClassSelector selector = selectClass(MyTestClass.class);
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(4, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test2()"));
    assertThat(uniqueIds).contains(uniqueIdForTestFactoryMethod(MyTestClass.class, "dynamicTest()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 17 with UniqueId

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

the class TestClassWithTemplate method twoClassesResolution.

@Test
void twoClassesResolution() {
    ClassSelector selector1 = selectClass(MyTestClass.class);
    ClassSelector selector2 = selectClass(YourTestClass.class);
    resolver.resolveSelectors(request().selectors(selector1, selector2).build(), engineDescriptor);
    assertEquals(7, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test2()"));
    assertThat(uniqueIds).contains(uniqueIdForTestFactoryMethod(MyTestClass.class, "dynamicTest()"));
    assertThat(uniqueIds).contains(uniqueIdForClass(YourTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(YourTestClass.class, "test3()"));
    assertThat(uniqueIds).contains(uniqueIdForMethod(YourTestClass.class, "test4()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 18 with UniqueId

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

the class TestClassWithTemplate method resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithUnknownSegmentTypeResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = engineId().append("bogus", "enigma");
    UniqueIdSelector selector = selectUniqueId(uniqueId);
    EngineDiscoveryRequest request = request().selectors(selector).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could not be resolved.");
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LogRecord(java.util.logging.LogRecord) EngineDiscoveryRequest(org.junit.platform.engine.EngineDiscoveryRequest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) TrackLogRecords(org.junit.jupiter.engine.TrackLogRecords)

Example 19 with UniqueId

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

the class TestClassWithTemplate method methodResolutionByUniqueId.

@Test
void methodResolutionByUniqueId() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(MyTestClass.class, "test1()").toString());
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) 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)

Example 20 with UniqueId

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

the class TestClassWithTemplate method methodResolution.

@Test
void methodResolution() throws NoSuchMethodException {
    Method test1 = MyTestClass.class.getDeclaredMethod("test1");
    MethodSelector selector = selectMethod(test1.getDeclaringClass(), test1);
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(MyTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(MyTestClass.class, "test1()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) MethodSelector(org.junit.platform.engine.discovery.MethodSelector) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) JupiterUniqueIdBuilder.uniqueIdForMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForMethod) Method(java.lang.reflect.Method) JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestFactoryMethod) JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod(org.junit.jupiter.engine.discovery.JupiterUniqueIdBuilder.uniqueIdForTestTemplateMethod) 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