Prasanna
Prasanna

Reputation: 3771

Play Framework: Set environment for Integration test

I have an IntegrationSpec using Selenium in Play Framework 2.2.0 that I would like to run against multiple environments.

  1. In dev environment, I will start the test server and run the integration test against that server.
  2. In test environments, I won't start the test server but just run the test again each test environment. (For each environment, the URL is going to be different.)

First obvious choice is to pass the environment as system property through command line:

 play -Denv=test1 "test-only integration.IntegrationSpec"

But above does not work in Play 2.2. When in test, I try to read it as follows and the value returned is null.

System.getProperty("env")

I see the exact question being asked here but the answer is for older versions. In 2.2 it does not seem to work anymore.

Is there another way to set this property that I can use it in my test?

Upvotes: 1

Views: 354

Answers (1)

Rado Buransky
Rado Buransky

Reputation: 3294

My understanding is that tests run in forked JVM and that's why the property is not set. You may pass the "env" parameter by adding following to your build.sbt:

javaOptions in Test += "-Denv=" + Option(System.getProperty("env")).getOrElse("default")

Upvotes: 2

Related Questions