Gradle: additional test source folders

Answered

Our workflow is to create our project configuration in gradle and then import to IDEA using IDEA gradle support, rather than using the gradle IDEA plugin to generate the project/modules.

We are trying to set up multiple test source sets to support unit and integration testing. We add the integration-test sourceSet:

sourceSets {
  integrationTest {
    java {
      compileClasspath += main.output + test.output
      runtimeClasspath += main.output + test.output
      srcDir file('src/integration-test/java')
    }
    resources.srcDir file('src/integration-test/resources')
  }
}
 
IDEA picks up the new sourceSet as "source folders" (blue) rather than "test source folders" (green). Is there a way to force IDEA to import this sourceSet as test source folders (and resources)?
0
9 comments

I struggle to make this work, without success. I have added configuration based on the suggestion in the comment link above, but IDEA still picks up src/it/scala as a Source folder and src/it/resources as Resources folder.

I use IDEA 2018.1.3 and Gradle 4.8. 

Any suggestions?

0
Avatar
Vladislav Soroka

If you want to mark the `scala` plugin source folders of the project as the tests add them to `testSourceDirs` as well:

apply plugin: 'idea'
idea {
module {
testSourceDirs += project.sourceSets.integrationTest.java.srcDirs
testSourceDirs += project.sourceSets.integrationTest.scala.srcDirs
testSourceDirs += project.sourceSets.integrationTest.resources.srcDirs
}
}
0

Yes, that is what I did. It simply doesn't work. I'll try to create a public repo that exposes the problem.

0
Avatar
Permanently deleted user

Any update on this? in my case the IDEA is marking the integration tests source folder as green but it is not using the Gradle Test runner to run them, but uses the internal test runner  

0

You can use the corresponding Gradle task from the Gradle projects tool window to run the tests via Gradle Test runner. Another option is to delegate build/run actions to Gradle.

0
Avatar
Permanently deleted user

I am delegating to Gradle, this is only working for the tests in the `test` source folder but not in other source folders.

It is using the IDEA tests runner even if i configure it to use the gradle one

0

If this setting has no effect (https://i.imgur.com/ZGnlnRJ.png), please file a bug at https://youtrack.jetbrains.com/issues/IDEA with the sample project to reproduce attached.

0
Avatar
Permanently deleted user

It is working only for tests in the test source set.

 

Done, https://youtrack.jetbrains.com/issue/IDEA-195896

0

Please sign in to leave a comment.