'src/test/resources' fails in Gradle Multi-module project

Answered

I have a Gradle multi-project configuration where my sub-project tests are not able to access `src/test/resources` for their individual projects.

This has been working in the past and I do have it working for some of my older projects that I imported but I can't determine what the difference is between the projects since they were copied from one another.

Steps to reproduce:

  1. Create a Gradle mulit-project project using Groovy
  2. Create test files in one of the sub-project's src/test/resources directory.
  3. Attempt to access the file in a Spock Unit Test (probably any Unit Test).
  4. Observe: java.io.FileNotFoundException: src/test/resources/test-file.json (No such file or directory)

The same tests work when run using Gradle from the command line.  If I have IDEA delegate to the Gradle test runner it still fails.  I prefer to use the Platform Test Runner as it is significantly quicker but neither works from inside the IDE.

The root of the problem seems to be the base path used when the tests are run.  For a test, I created a project called "idea-resources-issue" with a sub-project called "core".  When I inspect where the test runner is looking for the `src/test/resources` files it is looking in: /home/mike/git/idea-resources-issue/.idea/modules/core/.   It should be /home/mike/git/idea-resources/core/.

If it helps to pass along the project, I can spend some time to get rid of my proprietary code so I can share.

0
7 comments

What IDE version do you use? What Run/Debug Configuration do you use?

Please check if this is the case: https://youtrack.jetbrains.com/issue/IDEA-182950#comment=27-2571055 (to fix, set %MODULE_WORKING_DIR% for the Working directory JUnit Configuration).

0
Avatar
Permanently deleted user

IntelliJ IDEA 2018.1.2 (Ultimate Edition)
Build #IU-181.4668.68, built on April 24, 2018
JRE: 1.8.0_152-release-1136-b29 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-41-generic

I use the Run/Debug configuration created when I right-click on the test(s) and/or whatever is used when I click the run button in the gutter next to individual tests. Here's a screen grab of the config for my failing test:

0
Avatar
Permanently deleted user

I just confirmed that changing the Working directory: setting to %MODULE_WORKING_DIR% does fix the problem and it seems to work for both the Platform Test Runner (preferred) and the Gradle runner.

This is workable but it would be better if this were the default setting when a Gradle project was imported, is there a ticket I can follow for that?

 

0

Thanks for the information. Yes, defaults will be changed. We have fixed it in 2018.1.4 version: https://youtrack.jetbrains.com/issue/IDEA-190100 (to be released soon).

0
Avatar
Permanently deleted user

That's great.  As always, thanks for the prompt response on these forums.

0

Can you make the same thing happen for ScalaTests?  This fails with scala tests because MODULE_WORKING_DIR does not exist.

0

Please sign in to leave a comment.