Search in sources :

Example 96 with UniqueId

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

the class OtherClass method methodResolutionByUniqueIdWithMissingMethodName.

@Test
void methodResolutionByUniqueIdWithMissingMethodName() {
    UniqueId uniqueId = uniqueIdForMethod(getClass(), "()");
    resolve(request().selectors(selectUniqueId(uniqueId)));
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    var result = verifySelectorProcessed(selectUniqueId(uniqueId));
    assertThat(result.getStatus()).isEqualTo(FAILED);
    // 
    assertThat(result.getThrowable().get()).isInstanceOf(// 
    PreconditionViolationException.class).hasMessageStartingWith("Method [()] does not match pattern");
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 97 with UniqueId

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

the class OtherClass method methodOfInnerClassByUniqueId.

@Test
void methodOfInnerClassByUniqueId() {
    UniqueIdSelector selector = selectUniqueId(uniqueIdForMethod(OtherTestClass.NestedTestClass.class, "test5()").toString());
    resolve(request().selectors(selector));
    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 98 with UniqueId

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

the class OtherClass method resolvingUniqueIdWithWrongParamsResolvesNothing.

@Test
void resolvingUniqueIdWithWrongParamsResolvesNothing() {
    UniqueId uniqueId = uniqueIdForMethod(HerTestClass.class, "test7(java.math.BigDecimal)");
    resolve(request().selectors(selectUniqueId(uniqueId)));
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    assertUnresolved(selectUniqueId(uniqueId));
}
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 99 with UniqueId

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

the class OtherClass method methodResolutionByUniqueIdWithBogusParameters.

@Test
void methodResolutionByUniqueIdWithBogusParameters() {
    UniqueId uniqueId = uniqueIdForMethod(getClass(), "methodName(java.lang.String, junit.foo.Enigma)");
    resolve(request().selectors(selectUniqueId(uniqueId)));
    assertTrue(engineDescriptor.getDescendants().isEmpty());
    var result = verifySelectorProcessed(selectUniqueId(uniqueId));
    assertThat(result.getStatus()).isEqualTo(FAILED);
    // 
    assertThat(result.getThrowable().get()).isInstanceOf(// 
    JUnitException.class).hasMessage("Failed to load parameter type [%s] for method [%s] in class [%s].", "junit.foo.Enigma", "methodName", getClass().getName());
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) JUnitException(org.junit.platform.commons.JUnitException) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 100 with UniqueId

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

the class OtherClass method resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory.

@Test
void resolvingDynamicTestByUniqueIdResolvesUpToParentTestFactory() {
    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");
    resolve(request().selectors(selectUniqueId(dynamicTestUid)));
    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, 42)).isTrue();
    assertThat(dynamicDescendantFilter.test(differentDynamicTestUid, 42)).isFalse();
    assertAllSelectorsResolved();
}
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)

Aggregations

UniqueId (org.junit.platform.engine.UniqueId)131 Test (org.junit.jupiter.api.Test)95 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)83 DynamicTest (org.junit.jupiter.api.DynamicTest)64 TestDescriptor (org.junit.platform.engine.TestDescriptor)29 UniqueIdSelector (org.junit.platform.engine.discovery.UniqueIdSelector)25 ClassSelector (org.junit.platform.engine.discovery.ClassSelector)15 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)14 List (java.util.List)9 JupiterTestDescriptor (org.junit.jupiter.engine.descriptor.JupiterTestDescriptor)8 TestTemplateInvocationTestDescriptor (org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor)8 TestPlan (org.junit.platform.launcher.TestPlan)8 JUnitException (org.junit.platform.commons.JUnitException)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 Optional (java.util.Optional)6 DynamicDescendantFilter (org.junit.jupiter.engine.descriptor.DynamicDescendantFilter)6 TestEngine (org.junit.platform.engine.TestEngine)6 TrackLogRecords (org.junit.jupiter.engine.TrackLogRecords)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5