I develop a Scala project in IntelliJ IDEA (GitHub repository). The project is built with Gradle 4.3 and uses ScalaTest plus its latest Gradle plugin for testing (id 'com.github.maiflai.scalatest' version '0.19'
). The version of the Scala plug-in is 2017.3.11.1
The project has two levels of hierarchy: the parent project at the root level and the subprojects as the children. The tests use input files that are located in the root level (e.g. the ./compiler/
dir's project uses files from the ./queries/
dir). Tests refer to the files with relative paths: for example, if the compiler uses query files, it refers to them as ../queries/query-file.ext
.
With this setup, tests work fine from the command line when running ./gradlew test
. However, when I run a new test form IntelliJ, the working directory is always set to the root level, which breaks the tests. (Of course, this can be fixed manually, but this has to be done for each test executed). Note that I imported the project to IntelliJ IDEA using the "Create separate module per source set" setting (because of issue SCL-12718, which is not yet fixed in stable - and I am unsure whether this will fix the problem).
Is there a way to fix or work around this? Updating the ScalaTest Gradle configuration to use the directory of the current subproject or reconfiguring IntelliJ to use the directory of the parent project would both work for me.
You can change the default working dir for the tests in IntelliJ by doing:
It would probably be better to change the tests to not rely on the working directory though. If you access the "queries" files as JVM resources instead of opening them by relative path, it should work in both environments. See How do I load a file from resource folder?