Search in sources :

Example 11 with UniqueIdSelector

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

the class TestClassWithTemplate method classResolutionByUniqueId.

@Test
void classResolutionByUniqueId() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForClass(MyTestClass.class).toString());
    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 : 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 12 with UniqueIdSelector

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

the class TestClassWithTemplate method methodResolutionByUniqueIdFromInheritedClass.

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

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

the class TestClassWithTemplate method nestedTestResolutionFromUniqueIdToMethod.

@Test
void nestedTestResolutionFromUniqueIdToMethod() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(TestCaseWithNesting.NestedTestCase.class, "testB()").toString());
    resolver.resolveSelectors(request().selectors(selector).build(), engineDescriptor);
    List<UniqueId> uniqueIds = uniqueIds();
    assertEquals(3, uniqueIds.size());
    assertThat(uniqueIds).contains(uniqueIdForClass(TestCaseWithNesting.class));
    assertThat(uniqueIds).contains(uniqueIdForClass(TestCaseWithNesting.NestedTestCase.class));
    assertThat(uniqueIds).contains(uniqueIdForMethod(TestCaseWithNesting.NestedTestCase.class, "testB()"));
}
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 14 with UniqueIdSelector

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

the class TestClassWithTemplate method twoMethodResolutionsByUniqueId.

@Test
void twoMethodResolutionsByUniqueId() {
    UniqueIdSelector selector1 = selectUniqueId(uniqueIdForMethod(MyTestClass.class, "test1()").toString());
    UniqueIdSelector selector2 = selectUniqueId(uniqueIdForMethod(MyTestClass.class, "test2()").toString());
    // adding same selector twice should have no effect
    resolver.resolveSelectors(request().selectors(selector1, selector2, selector2).build(), engineDescriptor);
    assertEquals(3, 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()"));
    TestDescriptor classFromMethod1 = descriptorByUniqueId(uniqueIdForMethod(MyTestClass.class, "test1()")).getParent().get();
    TestDescriptor classFromMethod2 = descriptorByUniqueId(uniqueIdForMethod(MyTestClass.class, "test2()")).getParent().get();
    assertEquals(classFromMethod1, classFromMethod2);
    assertSame(classFromMethod1, classFromMethod2);
}
Also used : UniqueIdSelector(org.junit.platform.engine.discovery.UniqueIdSelector) DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) 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)

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