Problem Setting Classpath For System Tests in IntelliJ
Hi, I hope this is a simple question, because this seems like something that shouldn't be difficult.
I've got a standard Gradle project with the normal layout:
./src/main/groovy
./src/main/resources
./src/test/java
./src/test/resources
And I've created a Gradle task for system tests as follows:
sourceSets {
systemTest {
groovy.srcDir file('src/system-test/groovy')
resources.srcDir file('src/system-test/resources')
}
}
And this matches the folders in my project:
./src/system-test/groovy
./src/system-test/resources
And when I import the project into IntelliJ, it seems to figure all of that out ok because when I look at the Module Settings, I see all those folders listed appropriately. For example, in the Modules section on the Sources tab, it lists './src/system-test/resources' and './src/test/resources' as Test Resource Folders. So everything looks good.
Here is my problem. My unit tests read from the test resource folder with no problem. And if I run the system tests from the command line using my Gradle task, it finds the appropriate configuration. However, when I run the system test from IntelliJ, it does not find any of the configuration files located in the system-test/resources folder. If I move the configuration files over to the test/resources folder, it finds them.
This is a problem because the configurations for unit tests and system tests are drastically different. The unit tests are using mocks. The system tests are designed to be more end to end tests and thus wire in the actual implementations instead of mocks. So I'd really like to keep the configurations separate.
I've Googled for any discussion on this I can find. Saw some threads on Eclipse being able to "add resource folder" or something like that to the classpath. I was hoping there was something similar in my favorite ide, IntelliJ. Any clues?
Please sign in to leave a comment.
Hi Michael,
There is a limited support for gradle custom sourcesets in IDEA.
During gradle project import, IntelliJ creates one IDEA module per gradle project, but gradle project supports several source sets with a different classpath.
Initially, it has been caused by the gradle tooloing api limitation (feel free to watch/vote up https://issues.gradle.org/browse/GRADLE-2680)
However, IDEA 13/14 can resolve source folders of these sources sets, using custom gradle tooling models.
But, it's still not possible to resolve dependencies of custom sources set for IDEA within current modules structure approach w/o possible breakage of classpath for IDEA module(which is based on 'main' source set dependencies).
Since IDEA doesn't support custom scopes for its source folders (there are only 4 scopes: Compile, Test, Runtime, Provided).
Possible fix would be to create a separate IDEA module for each gradle source set.
The feature is planned, but ETA is unclear at the moment. You can watch/vote for it at https://youtrack.jetbrains.com/issue/IDEA-138076
As a workaround you could add the following to your gradle scripts:
Note, this will affect main test classpath also!
Also, you could consider to use Gradle test runner in IDEA (instead of Junit runner).
To make possible invocation of system tests using gradle test runner, add the following: