Search in sources :

Example 1 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class JupiterTestEngine method discover.

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
    JupiterConfiguration configuration = new CachingJupiterConfiguration(new DefaultJupiterConfiguration(discoveryRequest.getConfigurationParameters()));
    JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(uniqueId, configuration);
    new DiscoverySelectorResolver().resolveSelectors(discoveryRequest, engineDescriptor);
    return engineDescriptor;
}
Also used : DiscoverySelectorResolver(org.junit.jupiter.engine.discovery.DiscoverySelectorResolver) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) CachingJupiterConfiguration(org.junit.jupiter.engine.config.CachingJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) JupiterEngineDescriptor(org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor)

Example 2 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class ExtensionContextTests method configurationParameter.

@TestFactory
Stream<DynamicTest> configurationParameter() throws Exception {
    JupiterConfiguration echo = new DefaultJupiterConfiguration(new EchoParameters());
    String key = "123";
    Optional<String> expected = Optional.of(key);
    UniqueId engineUniqueId = UniqueId.parse("[engine:junit-jupiter]");
    JupiterEngineDescriptor engineDescriptor = new JupiterEngineDescriptor(engineUniqueId, configuration);
    UniqueId classUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]");
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(classUniqueId, getClass(), configuration);
    Method method = getClass().getDeclaredMethod("configurationParameter");
    UniqueId methodUniqueId = UniqueId.parse("[engine:junit-jupiter]/[class:MyClass]/[method:myMethod]");
    TestMethodTestDescriptor methodTestDescriptor = new TestMethodTestDescriptor(methodUniqueId, getClass(), method, configuration);
    return // 
    Stream.of(// 
    (ExtensionContext) new JupiterEngineExtensionContext(null, engineDescriptor, echo, null), // 
    new ClassExtensionContext(null, null, classTestDescriptor, echo, null, 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) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) JupiterConfiguration(org.junit.jupiter.engine.config.JupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) TestFactory(org.junit.jupiter.api.TestFactory)

Example 3 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithConfigParamSet.

@Test
void getTestInstanceLifecycleWithConfigParamSet() {
    ConfigurationParameters configParams = mock(ConfigurationParameters.class);
    when(configParams.get(KEY)).thenReturn(Optional.of(PER_CLASS.name().toLowerCase()));
    Lifecycle lifecycle = getTestInstanceLifecycle(getClass(), new DefaultJupiterConfiguration(configParams));
    assertThat(lifecycle).isEqualTo(PER_CLASS);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleFromMetaAnnotationWithNoConfigParamSet.

@Test
void getTestInstanceLifecycleFromMetaAnnotationWithNoConfigParamSet() {
    Class<?> testClass = BaseMetaAnnotatedTestCase.class;
    Lifecycle lifecycle = getTestInstanceLifecycle(testClass, new DefaultJupiterConfiguration(mock(ConfigurationParameters.class)));
    assertThat(lifecycle).isEqualTo(PER_CLASS);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with DefaultJupiterConfiguration

use of org.junit.jupiter.engine.config.DefaultJupiterConfiguration in project junit5 by junit-team.

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecyclePreconditions.

@Test
void getTestInstanceLifecyclePreconditions() {
    PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> getTestInstanceLifecycle(null, new DefaultJupiterConfiguration(mock(ConfigurationParameters.class))));
    assertThat(exception).hasMessage("testClass must not be null");
    exception = assertThrows(PreconditionViolationException.class, () -> getTestInstanceLifecycle(getClass(), null));
    assertThat(exception).hasMessage("configuration must not be null");
}
Also used : DefaultJupiterConfiguration(org.junit.jupiter.engine.config.DefaultJupiterConfiguration) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) PreconditionViolationException(org.junit.platform.commons.PreconditionViolationException) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultJupiterConfiguration (org.junit.jupiter.engine.config.DefaultJupiterConfiguration)9 Test (org.junit.jupiter.api.Test)6 Lifecycle (org.junit.jupiter.api.TestInstance.Lifecycle)5 TestInstanceLifecycleUtils.getTestInstanceLifecycle (org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle)5 JupiterConfiguration (org.junit.jupiter.engine.config.JupiterConfiguration)3 ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)3 CachingJupiterConfiguration (org.junit.jupiter.engine.config.CachingJupiterConfiguration)2 UniqueId (org.junit.platform.engine.UniqueId)2 Resources (com.google.common.io.Resources)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1