Intellij 和 sbt:如何让 intellij 为我的播放应用程序测试读取自定义配置文件?

Intellij and sbt: How to make intellij to read custom configuration file for my play application tests?

对于我的测试(Play Framework 2.6 应用程序),我想使用不同的配置文件。

为此,我将以下行添加到 build.sbt

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

当我从 sbt (sbt test) 运行 测试时,它工作正常,读取自定义配置文件。

但是当 运行ning 从 IntelliJ IDEA 进行测试时,它会忽略此设置并使用 application.conf 文件。

如何强制 IntelliJ 使用这个 sbt 设置?

您必须编辑您的 intellij 配置。 为此,请使用:https://www.jetbrains.com/help/idea/creating-and-editing-run-debug-configurations.html.

进入编辑配置页面后,将 ScalaTest 添加到配置列表中。然后在VM Parameters下添加-Dconfig.file=conf/application.test.conf

保存,大功告成!