Search code examples
javatestingplayframeworksystem-properties

Pass System Properties in Play Framework Test with Activator


Play framework uses

activator test

to run all tests.

How do I pass Java System properties to my test cases. The following won't work

activator -Dsettings="/settings/settings.json" test

Coincidentally, the above will work if I am using the ~runcommand instead.

I've already read this question, but it is only valid for the play command


Solution

  • I think I found a solution (Play 2.3.8)

    In build.sbt add something like this:

    javaOptions in Test += "-Dsettings=" + Option(System.getProperty("settings")).getOrElse("default.json")
    

    then

    activator -Dsettings="/settings/settings.json" test
    

    can override the settings key

    Disclaimer: I tested this for testserver.port, not for settings