Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring IntelliJ so it takes a specific configuration file to run tests?

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!

like image 424
Thomas Avatar asked Jan 12 '15 13:01

Thomas


1 Answers

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.

like image 126
Javaru Avatar answered Sep 22 '22 01:09

Javaru