How can I create a FakeApplication
to run my tests using my dev.conf
instead of the default application.conf
?
My current test consists of the following construct:
Map<String, String> map = new HashMap<>();
map.put("config.file", "/path/to/dev.conf");
FakeApplication fakeApplication = fakeApplication(map);
TestServer testServer = testServer(3333, fakeApplication);
// testServer.start();
running(testServer, HTMLUNIT, new F.Callback<TestBrowser>() {
public void invoke(TestBrowser browser) {
//do something
}
});
This code adapted from the Play Framework Documentation about writing test throws the following Exception, as the default application.conf
does not work on my development-system. If I uncomment testServer.start();
I can see it even more clearly.
[WARN] [01/01/2013 18:36:59.505] [pool-4-thread-3] [Dispatchers] Dispatcher [akka.actor.promises-dispatcher] not configured, using default-dispatcher
[WARN] [01/01/2013 18:36:59.521] [play-akka.actor.default-dispatcher-2] [Dispatchers] Dispatcher [akka.actor.actions-dispatcher] not configured, using default-dispatcher
[error] Test test.ApplicationTest.runInBrowser failed: Server is not started!
[error] at scala.sys.package$.error(package.scala:27)
[error] at play.api.test.TestServer.stop(Selenium.scala:117)
[error] at play.test.Helpers.stop(Helpers.java:325)
[error] at play.test.Helpers.running(Helpers.java:355)
[error] at test.ApplicationTest.runInBrowser(ApplicationTest.java:74)
[error] ...
I assume the line
map.put("config.file", "/path/to/dev.conf");
is wrong and has to be adapted. But how?
I have the same issue and I did something like this to solve it:
where application.dev.conf can be whaterver config file you want to set in there.
You may also want to check out this option:
http://alexgaribay.com/2015/02/05/overwrite-settings-for-testing-in-play-framework/
It is impossible to substitute main config with another this way. You only could override specific settings by passing a map to
fakeApplication
.I.e. if you config contains:
You can override it by placing new values inside a map:
I think you might want to run your test command as follows:
play -Dconfig.file=path/to/dev.conf test