view raw
Itchy Itchy - 7 months ago 32
Java Question

FakeApplication using a specific application.conf?

How can I create a

to run my tests using my
instead of the default

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
does not work on my development-system. If I uncomment
I can see it even more clearly.

[WARN] [01/01/2013 18:36:59.505] [pool-4-thread-3] [Dispatchers] Dispatcher [] not configured, using default-dispatcher
[WARN] [01/01/2013 18:36:59.521] [] [Dispatchers] 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(
[error] at play.test.Helpers.running(
[error] at test.ApplicationTest.runInBrowser(
[error] ...

I assume the line

map.put("config.file", "/path/to/dev.conf");

is wrong and has to be adapted. But how?


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:

mongodb.default.uri = ...
logger.root = ERROR

You can override it by placing new values inside a map:

Map<String, String> map = new HashMap<>();
map.put("mongodb.default.uri", "...");
map.put("logger.root", "INFO");

FakeApplication fakeApplication = fakeApplication(map);