Resources and classpath when running test

I have a problem with resource files not being added to the classpath when I run a test from within IDEA. I thought that the "Test Source Folders" would automatically be added to the classpath, through the "Module Source" in the Dependencies tab, when I run a test, but it does not seem to work.

I do not "Make" Before Launch when I run the JUnit test (the project is built externally), but I did not think this would affect anything. However, when I check the "Make" box, all my files in the "src\test\resources" folder are copied flatly to my "Test output path", and hence are a part of my classpath.

Any help would be highly appreciated!


I have the following setup for my project
pic 2012-02-09_02.jpg

pic 2012-02-09_04.jpg

pic 2012-02-09_06.jpg

pic 2012-02-09_05.jpg

Comment actions Permalink

IDEA doesn't support such set up. You should include copying resources to the output directory of your external build or you should use IDEA's make. IDEA includes in the classpath only output directories as we do not make a difference between source root with java files and with resources on that level.
Sorry for the inconvenience

Comment actions Permalink

ok, thank you for your reply.

I use gradle to build my project, but all I want to do is to make IDEA aware of the project resources (xml-files). Could I use the "VM options" under the JUnit-configuration tab to extend the module classpath? Or would the classpath in the VM options just override my module classpath?

I assume that I could make the gradle Java plugin task processTestResources copy the files to the classpath, but I would not like to tamper with the build-process, as I feel this is an IDEA-specific problem. (Eclipse handles the setup just fine).

Any suggestions on how I could add an arbitrary directory to the classpath when running tests?

Comment actions Permalink

I solved the problem by adding the following to VM options:


somewhat dirty, but I could not find out how to make my module classpath include a resources directory

any other suggestions?


Please sign in to leave a comment.