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
}
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))));
}
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());
}
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);
}
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()"));
}
Aggregations