Search in sources :

Example 11 with ConfigurationParameters

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

the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam.

@Test
void getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam() {
    ConfigurationParameters configParams = mock(ConfigurationParameters.class);
    when(configParams.get(KEY)).thenReturn(Optional.of(PER_CLASS.name().toLowerCase()));
    Lifecycle lifecycle = getTestInstanceLifecycle(TestCase.class, configParams);
    assertThat(lifecycle).isEqualTo(PER_METHOD);
}
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 12 with ConfigurationParameters

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

the class DefaultLauncherTests method withConfigurationParameters_launcherPassesPopulatedConfigurationParametersIntoTheExecutionRequest.

@Test
void withConfigurationParameters_launcherPassesPopulatedConfigurationParametersIntoTheExecutionRequest() {
    TestEngineSpy engine = new TestEngineSpy();
    DefaultLauncher launcher = createLauncher(engine);
    launcher.execute(request().configurationParameter("key", "value").build());
    ConfigurationParameters configurationParameters = engine.requestForExecution.getConfigurationParameters();
    assertThat(configurationParameters.size()).isEqualTo(1);
    assertThat(configurationParameters.get("key").isPresent()).isTrue();
    assertThat(configurationParameters.get("key").get()).isEqualTo("value");
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurationParameters

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

the class DefaultLauncherTests method withoutConfigurationParameters_LookupFallsBackToSystemProperty.

@Test
void withoutConfigurationParameters_LookupFallsBackToSystemProperty() {
    System.setProperty(FOO, BAR);
    try {
        TestEngineSpy engine = new TestEngineSpy();
        DefaultLauncher launcher = createLauncher(engine);
        launcher.execute(request().build());
        ConfigurationParameters configurationParameters = engine.requestForExecution.getConfigurationParameters();
        assertThat(configurationParameters.size()).isEqualTo(0);
        Optional<String> optionalFoo = configurationParameters.get(FOO);
        assertTrue(optionalFoo.isPresent(), "foo should have been picked up via system property");
        assertEquals(BAR, optionalFoo.get(), "foo property");
    } finally {
        System.clearProperty(FOO);
    }
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) TestEngineSpy(org.junit.platform.engine.test.TestEngineSpy) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigurationParameters

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

the class LauncherConfigurationParametersTests method systemProperty.

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

Example 15 with ConfigurationParameters

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

the class LauncherConfigurationParametersTests method getPreconditions.

@Test
void getPreconditions() {
    ConfigurationParameters configParams = fromMap(emptyMap());
    assertThrows(PreconditionViolationException.class, () -> configParams.get(null));
    assertThrows(PreconditionViolationException.class, () -> configParams.get(""));
    assertThrows(PreconditionViolationException.class, () -> configParams.get("  "));
}
Also used : ConfigurationParameters(org.junit.platform.engine.ConfigurationParameters) Test(org.junit.jupiter.api.Test)

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