13

I am using Play Framework 2.3 and IntelliJ IDEA 14. I use a Mailer plugin in my application. I wrote a few functional tests that work perfectly when I run the test command in the SBT console, after adding this line to build.sbt:

javaOptions in Test += "-Dconfig.file=conf/application.test.conf"

And this one to the file conf/application.test.conf:

smtp.mock=yes

Unfortunately, when I run tests directly from IntelliJ, I get this error:

java.lang.RuntimeException: smtp.host needs to be set in application.conf in order to use this plugin (or set smtp.mock to true)

I tried launching those tests with the VM argument -Dconfig.file=conf/application.test.conf, without success.

Here are two examples of the tests I am trying to execute:

@Test
public void testWithServer() {
    running(testServer(3333), () -> {
        assertThat(WS.url("http://localhost:3333").get().get(1000).getStatus()).isEqualTo(OK);
    });
}

@Test
public void testWithBrowser() {
    running(testServer(3333), HTMLUNIT, browser -> {
        browser.goTo("http://localhost:3333");
        assertThat(browser.$("title").getText()).isEqualTo("Welcome");
    });
}

Can anyone help me on this?

Thanks!

Thomas
  • 1,491
  • 13
  • 23

2 Answers2

10

Unless I am mistaken, the config.file setting, and thus the conf/application.test.conf file, is used by SBT. As such, IntelliJ IDEA when running the test does not load it and its contained settings even when you specify the config.file setting via the VM Options text field. Instead, you must put the -Dsmtp.mock=yes setting (any any other settings that are in the application.test.conf file) in the VM Options text field.

If that works, you can add the argument(s) to the VM Options text field to the JUnit settings under the Default group in the Run/Debug Configuration dialog so any new tests you create will have it preset.

Javaru
  • 30,412
  • 11
  • 93
  • 70
  • I was hoping that something could make IntelliJ take any config file, but this works so thanks a lot. And you're right, this file is used by SBT. – Thomas Jan 12 '15 at 22:48
  • You should [open a feature request](https://youtrack.jetbrains.com) asking that test & application run/debug configurations be able to take a configuration file for setting VM options. I think that would be a great enhancement. Post the request's ID/link here and I'd certainly vote for it. Others would likely as well. – Javaru Jan 13 '15 at 14:37
  • You could also add the option -Dconfig.file directly into VM options, that's what I do and it works well, just be sure to set the absolute path, relative doesn't work for me. – Aphax Apr 28 '16 at 11:20
4

In your run configurations, select JUnit, and then click the wrench to edit the default config. Then, in VM options, add -Dconfig.file=/absolute/path/to/application.test.conf.

kdazzle
  • 4,190
  • 3
  • 24
  • 27