Integration Testing: Setting System Properties Before DeltaSpike

DeltaSpike's Test-Control Module loads the unit test after the injected classes. Therefore any configured system properties set in @Before or even @BeforeClass are not going to be considered.

To test the underlying class:

public class SystemPropertyExposer {

    public String expose() {
        return System.getProperty("dev");


with e.g:

public class SystemPropertyExposerIT {

    String developer;

    public void developerInjection() {
        assertThat(developer, is("duke"));


You will have to set the property, before the initialization of SystemPropertyExposer.

This can be achieved with the following workaround:

import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner;
import org.junit.runners.model.InitializationError;

public class PropertiesLoaderTestRunner extends CdiTestRunner {

    static {
        System.setProperty("dev", "duke");

    public PropertiesLoaderTestRunner(Class testClass) throws InitializationError {


The sample above was pushed into:

See you at Java EE Workshops at Munich Airport, Terminal 2 and particularly at Continuous Java EE 7 Testing and Quality.


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments