Search in sources :

Example 11 with UniqueId

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

the class TestClassWithTemplate method testTemplateMethodResolutionByUniqueId.

@Test
void testTemplateMethodResolutionByUniqueId() {
    Class<?> clazz = TestClassWithTemplate.class;
    UniqueId templateUid = uniqueIdForTestTemplateMethod(clazz, "testTemplate()");
    resolver.resolveSelectors(request().selectors(selectUniqueId(templateUid)).build(), engineDescriptor);
    assertThat(engineDescriptor.getDescendants()).hasSize(2);
    assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), templateUid);
}
Also used : 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 12 with UniqueId

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

the class TestMethodFilterTests method newTestMethodDescriptor.

private static TestMethodTestDescriptor newTestMethodDescriptor() throws Exception {
    UniqueId uniqueId = UniqueId.forEngine("method");
    Class<TestClass> testClass = TestClass.class;
    Method testMethod = testClass.getMethod("testMethod");
    return new TestMethodTestDescriptor(uniqueId, testClass, testMethod);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Method(java.lang.reflect.Method) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)

Example 13 with UniqueId

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

the class TestEngineSpy method discover.

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    this.discoveryRequestForDiscovery = discoveryRequest;
    this.uniqueIdForDiscovery = uniqueId;
    UniqueId engineUniqueId = UniqueId.forEngine(ID);
    TestDescriptorStub engineDescriptor = new TestDescriptorStub(engineUniqueId, ID);
    TestDescriptorStub testDescriptor = new TestDescriptorStub(engineUniqueId.append("test", "test"), "test");
    engineDescriptor.addChild(testDescriptor);
    return engineDescriptor;
}
Also used : UniqueId(org.junit.platform.engine.UniqueId)

Example 14 with UniqueId

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

the class TestClassWithTemplate method packageResolutionUsingExplicitBasePackage.

@Test
void packageResolutionUsingExplicitBasePackage() {
    PackageSelector selector = selectPackage("org.junit.jupiter.engine.descriptor.subpackage");
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    assertEquals(6, engineDescriptor.getDescendants().size());
    List<UniqueId> uniqueIds = uniqueIds();
    assertThat(uniqueIds).contains(uniqueIdForClass(Class1WithTestCases.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(Class1WithTestCases.class, "test1()"));
    assertThat(uniqueIds).contains(uniqueIdForClass(Class2WithTestCases.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(Class2WithTestCases.class, "test2()"));
    assertThat(uniqueIds).contains(uniqueIdForMethod(ClassWithStaticInnerTestCases.ShouldBeDiscovered.class, "test1()"));
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) Class2WithTestCases(org.junit.jupiter.engine.descriptor.subpackage.Class2WithTestCases) PackageSelector(org.junit.platform.engine.discovery.PackageSelector) Class1WithTestCases(org.junit.jupiter.engine.descriptor.subpackage.Class1WithTestCases) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 15 with UniqueId

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

the class TestClassWithTemplate method resolvingUniqueIdWithWrongParamsResolvesNothing.

@Test
@TrackLogRecords
void resolvingUniqueIdWithWrongParamsResolvesNothing(LogRecordListener listener) {
    UniqueId uniqueId = uniqueIdForMethod(HerTestClass.class, "test7(java.math.BigDecimal)");
    EngineDiscoveryRequest request = request().selectors(selectUniqueId(uniqueId)).build();
    resolver.resolveSelectors(request, engineDescriptor);
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    // 
    assertThat(listener.stream(JavaElementsResolver.class, Level.WARNING).map(LogRecord::getMessage)).contains("Unique ID '" + uniqueId + "' could only be partially resolved. " + "All resolved segments will be executed; however, the following segments " + "could not be resolved: [Segment [type = 'method', value = 'test7(java.math.BigDecimal)']]");
}
Also used : 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)

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