Search in sources :

Example 1 with UniqueIdSelector

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

the class TestClassWithTemplate method methodOfInnerClassByUniqueId.

@Test
void methodOfInnerClassByUniqueId() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(OtherTestClass.NestedTestClass.class, "test5()").toString());
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(2, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(OtherTestClass.NestedTestClass.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(OtherTestClass.NestedTestClass.class, "test5()"));
}
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 2 with UniqueIdSelector

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

the class TestClassWithTemplate method methodResolutionByUniqueIdWithMissingMethodName.

@Test
void methodResolutionByUniqueIdWithMissingMethodName() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(getClass(), "()"));
    assertMethodDoesNotMatchPattern(selector);
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 3 with UniqueIdSelector

use of org.junit.platform.engine.discovery.UniqueIdSelector 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 4 with UniqueIdSelector

use of org.junit.platform.engine.discovery.UniqueIdSelector 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 5 with UniqueIdSelector

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

the class TestClassWithTemplate method methodResolutionByUniqueIdWithBogusParameters.

@Test
void methodResolutionByUniqueIdWithBogusParameters() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(getClass(), "methodName(java.lang.String, junit.foo.Enigma)"));
    Exception exception = assertThrows(JUnitException.class, () -> resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor));
    assertThat(exception).hasMessageStartingWith("Failed to load parameter type");
    assertThat(exception).hasMessageContaining("junit.foo.Enigma");
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) JUnitException(org.junit.platform.commons.JUnitException) PreconditionViolationException(org.junit.platform.commons.util.PreconditionViolationException) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

DynamicTest (org.junit.jupiter.api.DynamicTest)14 Test (org.junit.jupiter.api.Test)14 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)14 UniqueId (org.junit.platform.engine.UniqueId)10 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)10 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 LogRecord (java.util.logging.LogRecord)1 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)1 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)1 JUnitException (org.junit.platform.commons.JUnitException)1 PreconditionViolationException (org.junit.platform.commons.util.PreconditionViolationException)1 TestDescriptor (org.junit.platform.engine.TestDescriptor)1