use of org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor 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.jupiter.engine.descriptor.JupiterEngineDescriptor in project junit5 by junit-team.
the class JupiterTestEngine method discover.
@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(uniqueId);
new DiscoverySelectorResolver().resolveSelectors(discoveryRequest, engineDescriptor);
return engineDescriptor;
}
use of org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor in project junit5 by junit-team.
the class JupiterIntegrationTests method resolve.
@Test
void resolve() {
assumeTrue(getClass().getModule().isNamed(), "not running on the module-path");
ModuleSelector selector = DiscoverySelectors.selectModule(getClass().getModule().getName());
assertEquals(getClass().getModule().getName(), selector.getModuleName());
EngineDescriptor engine = new JupiterEngineDescriptor(UniqueId.forEngine(JupiterTestEngine.ENGINE_ID));
DiscoverySelectorResolver resolver = new DiscoverySelectorResolver();
resolver.resolveSelectors(request().selectors(selector).build(), engine);
// JupiterIntegrationTests.class
assertEquals(1, engine.getChildren().size());
// 5 test methods
assertEquals(5, getOnlyElement(engine.getChildren()).getChildren().size());
}
use of org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor in project junit5 by junit-team.
the class ExtensionContextTests method fromMethodTestDescriptor.
@Test
@SuppressWarnings("resource")
void fromMethodTestDescriptor() {
TestMethodTestDescriptor methodTestDescriptor = methodDescriptor();
ClassTestDescriptor classTestDescriptor = outerClassDescriptor(methodTestDescriptor);
JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(UniqueId.forEngine("junit-jupiter"));
engineDescriptor.addChild(classTestDescriptor);
Object testInstance = new OuterClass();
Method testMethod = methodTestDescriptor.getTestMethod();
JupiterEngineExtensionContext engineExtensionContext = new JupiterEngineExtensionContext(null, engineDescriptor, configParams);
ClassExtensionContext classExtensionContext = new ClassExtensionContext(engineExtensionContext, null, classTestDescriptor, configParams, null);
MethodExtensionContext methodExtensionContext = new MethodExtensionContext(classExtensionContext, null, methodTestDescriptor, configParams, testInstance, new ThrowableCollector());
// @formatter:off
assertAll("methodContext", () -> assertThat(methodExtensionContext.getElement()).contains(testMethod), () -> assertThat(methodExtensionContext.getTestClass()).contains(OuterClass.class), () -> assertThat(methodExtensionContext.getTestInstance()).contains(testInstance), () -> assertThat(methodExtensionContext.getTestMethod()).contains(testMethod), () -> assertThat(methodExtensionContext.getRequiredTestClass()).isEqualTo(OuterClass.class), () -> assertThat(methodExtensionContext.getRequiredTestInstance()).isEqualTo(testInstance), () -> assertThat(methodExtensionContext.getRequiredTestMethod()).isEqualTo(testMethod), () -> assertThat(methodExtensionContext.getDisplayName()).isEqualTo(methodTestDescriptor.getDisplayName()), () -> assertThat(methodExtensionContext.getParent()).contains(classExtensionContext), () -> assertThat(methodExtensionContext.getRoot()).isSameAs(engineExtensionContext));
// @formatter:on
}
use of org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor in project junit5 by junit-team.
the class ExtensionContextTests method fromJupiterEngineDescriptor.
@Test
void fromJupiterEngineDescriptor() {
JupiterEngineDescriptor engineTestDescriptor = new JupiterEngineDescriptor(UniqueId.root("engine", "junit-jupiter"));
JupiterEngineExtensionContext engineContext = new JupiterEngineExtensionContext(null, engineTestDescriptor, configParams);
// @formatter:off
assertAll("engineContext", () -> assertThat(engineContext.getElement()).isEmpty(), () -> assertThat(engineContext.getTestClass()).isEmpty(), () -> assertThat(engineContext.getTestInstance()).isEmpty(), () -> assertThat(engineContext.getTestMethod()).isEmpty(), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestClass()), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestInstance()), () -> assertThrows(PreconditionViolationException.class, () -> engineContext.getRequiredTestMethod()), () -> assertThat(engineContext.getDisplayName()).isEqualTo(engineTestDescriptor.getDisplayName()), () -> assertThat(engineContext.getParent()).isEmpty(), () -> assertThat(engineContext.getRoot()).isSameAs(engineContext));
// @formatter:on
}
Aggregations