Search in sources :

Example 6 with ConfigurationParameters

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

the class LauncherConfigurationParametersTests method explicitConfigParamOverridesSystemProperty.

@Test
void explicitConfigParamOverridesSystemProperty() {
    System.setProperty(KEY, SYSTEM_PROPERTY);
    ConfigurationParameters configParams = fromMap(singletonMap(KEY, CONFIG_PARAM));
    assertThat(configParams.get(KEY)).contains(CONFIG_PARAM);
    assertThat(configParams.toString()).contains(CONFIG_PARAM);
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 7 with ConfigurationParameters

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

use of org.junit.platform.engine.ConfigurationParameters 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(), configParams);
    assertThat(lifecycle).isEqualTo(PER_CLASS);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 9 with ConfigurationParameters

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

the class DiscoveryRequestCreatorTests method convertsConfigurationParameters.

@Test
void convertsConfigurationParameters() {
    options.setScanClasspath(true);
    options.setConfigurationParameters(mapOf(entry("foo", "bar"), entry("baz", "true")));
    LauncherDiscoveryRequest request = convert();
    ConfigurationParameters configurationParameters = request.getConfigurationParameters();
    assertThat(configurationParameters.size()).isEqualTo(2);
    assertThat(configurationParameters.get("foo")).contains("bar");
    assertThat(configurationParameters.getBoolean("baz")).contains(true);
}
Also used : LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

Example 10 with ConfigurationParameters

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

the class TestInstanceLifecycleUtilsTests method assertDefaultConfigParam.

private void assertDefaultConfigParam(String configValue, Lifecycle expected) {
    ConfigurationParameters configParams = mock(ConfigurationParameters.class);
    when(configParams.get(KEY)).thenReturn(Optional.ofNullable(configValue));
    Lifecycle lifecycle = getDefaultTestInstanceLifecycle(configParams);
    assertThat(lifecycle).isEqualTo(expected);
}
Also used : Lifecycle(org.junit.jupiter.api.TestInstance.Lifecycle) TestInstanceLifecycleUtils.getTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle) TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle(org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle) ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters)

Aggregations

ConfigurationParameters (org.junit.platform.engine.ConfigurationParameters)16 Test (org.junit.jupiter.api.Test)14 Lifecycle (org.junit.jupiter.api.TestInstance.Lifecycle)3 TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle (org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getDefaultTestInstanceLifecycle)3 TestInstanceLifecycleUtils.getTestInstanceLifecycle (org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle)3 TestEngineSpy (org.junit.platform.engine.test.TestEngineSpy)3 Method (java.lang.reflect.Method)1 TestFactory (org.junit.jupiter.api.TestFactory)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 ClassExtensionContext (org.junit.jupiter.engine.descriptor.ClassExtensionContext)1 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)1 JupiterEngineDescriptor (org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor)1 JupiterEngineExtensionContext (org.junit.jupiter.engine.descriptor.JupiterEngineExtensionContext)1 MethodExtensionContext (org.junit.jupiter.engine.descriptor.MethodExtensionContext)1 NestedClassTestDescriptor (org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor)1 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)1 UniqueId (org.junit.platform.engine.UniqueId)1 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)1