Search in sources :

Example 6 with UniqueId

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

the class XmlReportWriterTests method writesValidXmlEvenIfExceptionMessageContainsCData.

@Test
void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception {
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    AssertionError assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<![CDATA[", "<foo><![CDATA[bar]]]]><![CDATA[></foo>", "]]>").doesNotContain(assertionError.getMessage());
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 7 with UniqueId

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

the class ExtensionContextTests method configurationParameter.

@TestFactory
Stream<DynamicTest> configurationParameter() throws Exception {
    ConfigurationParameters echo = new EchoParameters();
    String key = "123";
    Optional<String> expected = Optional.of(key);
    UniqueId engineUniqueId = UniqueId.parse("[engine:junit-jupiter]");
    JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(engineUniqueId);
    UniqueId classUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(classUniqueId, getClass());
    Method method = getClass().getDeclaredMethod("configurationParameter");
    UniqueId methodUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]/[method:myMethod]");
    TestMethodTestDescriptor methodTestDescriptor = new TestMethodTestDescriptor(methodUniqueId, getClass(), method);
    return // 
    Stream.of(// 
    (ExtensionContext) new JupiterEngineExtensionContext(null, engineDescriptor, echo), // 
    new ClassExtensionContext(null, null, classTestDescriptor, echo, null), // 
    new MethodExtensionContext(null, null, methodTestDescriptor, echo, null, null)).map(context -> dynamicTest(context.getClass().getSimpleName(), () -> assertEquals(expected, context.getConfigurationParameter(key))));
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) Method(java.lang.reflect.Method) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) NestedClassTestDescriptor(org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor) MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) MethodExtensionContext(org.junit.jupiter.engine.descriptor.MethodExtensionContext) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) JupiterEngineExtensionContext(org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext) TestMethodTestDescriptor(org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor) TestFactory(org.junit.jupiter.api.TestFactory)

Example 8 with UniqueId

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

the class JupiterEngineExecutionContextTests method canOverrideAttributeWhenContextIsExtended.

@Test
void canOverrideAttributeWhenContextIsExtended() {
    UniqueId uniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(uniqueId, getClass());
    ClassExtensionContext extensionContext = new ClassExtensionContext(null, null, classTestDescriptor, configParams, null);
    ExtensionRegistry extensionRegistry = ExtensionRegistry.createRegistryWithDefaultExtensions(configParams);
    TestInstanceProvider testInstanceProvider = mock(TestInstanceProvider.class);
    ClassExtensionContext newExtensionContext = new ClassExtensionContext(extensionContext, null, classTestDescriptor, configParams, null);
    JupiterEngineExecutionContext newContext = // 
    originalContext.extend().withExtensionContext(// 
    extensionContext).withExtensionRegistry(// 
    extensionRegistry).withTestInstanceProvider(// 
    testInstanceProvider).build().extend().withExtensionContext(// 
    newExtensionContext).build();
    assertSame(newExtensionContext, newContext.getExtensionContext());
    assertSame(extensionRegistry, newContext.getExtensionRegistry());
    assertSame(testInstanceProvider, newContext.getTestInstanceProvider());
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ClassExtensionContext(org.junit.jupiter.engine.descriptor.ClassExtensionContext) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) Test(org.junit.jupiter.api.Test)

Example 9 with UniqueId

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

the class UniqueIdParsingForArrayParameterIntegrationTests method executeTestsForPrimitiveArrayMethodInjectionCases.

@Test
void executeTestsForPrimitiveArrayMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(PrimitiveArrayMethodInjectionTestCase.class);
    assertEquals(1, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(1, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(0, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    UniqueId uniqueId = eventRecorder.getExecutionEvents().stream().map(ExecutionEvent::getTestDescriptor).distinct().skip(2).map(TestDescriptor::getUniqueId).findFirst().orElseThrow(AssertionError::new);
    // @formatter:on
    assertThat(UniqueId.parse(uniqueId.toString())).isEqualTo(uniqueId);
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) TestDescriptor(org.junit.platform.engine.TestDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with UniqueId

use of org.junit.platform.engine.UniqueId 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)

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