JUnit tests do not use test resources properties files

When trying to run a JUnit test I'm getting the wrong values for a properties file. There are 2 versions of this file, one for the regular Java code and another for tests.

My project is built with gradle and I have correctly configured sourceSets for both main and test.

This very same config works fine on Intellij 13. Am I missing something?

3 comments
Comment actions Permalink

I have multi-module maven project and I wasn't able to run JUnit tests (resources and stuff wasn't being loaded) until I modifed the Working Directory in the Run Configurations dialogue.

It seems IntelliJ uses the top module level as the working directory. I just pointed that property to the sub-module directory where my test class is in.

Perhaps IntelliJ should be smart enough to do that by default for each maven sub module.

Regards.

1
Comment actions Permalink

I found the solution for my issue.

I was reading IDEA Gradle plugin documentation (https://gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html) and realised that I was specifying an "outputDir" but not a "testOutputDir".

Intellij 13 seems to not care much about it, but without the latter, Intellij is unable to scan the test classpath when running JUnit tests from the IDE.

Hope this helps

0
Comment actions Permalink

I meet the similar multi-module issue in the IntelliJ IDEA 2018.1 (CommunityEdition) on Windows 10 platform (MacOS 10.13 is working fine.)

 

In my case, the project has multiple Gradle modules, and resources weren't been load while JUnit tests running.

 

There is two way to fix it:

  • manually change the Working Directory
  • enable Delegate IDE build/run actions to gradle

 

0

Please sign in to leave a comment.