Gradle - how to run tests from another Gradle project and get coverage data

Does anyone know how to run tests from another gradle project and still get emma coverage reporting data?

Here is my current layout:

Root/ settings.gradle (no explicit build.gradle - just defines all subprojects) SubProjectA/ build.gradle src/ (all real source is here) SubProjectATest/ build.gradle src/ (all testing code is here) SubProjectB/ (similar structure as A) SubProjectBTest/ (similar structure as ATest) 

I am currently using the emma plugin and I would like to build SubProjectA and run all the tests in SubProjectATest from build.gradle for SubProjectA.

Here are some things I tried inside build.gradle for SubProjectA

  • testCompile project(':SubProjectATest').sourceSets.test.classes ( as suggested in this article ), but I got the error message β€œ Could not find property 'sourceSets' on project "
  • Just straight up to testCompile project(':SubProjectATest') , but then I get " ..SubProjectA/build/classes/test', not found " as well as "Skip task" :SubProjectA:compileTestJava' as it has no source files. "
  • Just add sourceSet as below:

    test {Java {srcDir '../SubProjectATest/src'}}

Adding the source set to (option 3) is the only option that worked, but it seems to be careless about it. Does anyone know how to do this using project dependencies?

Update # 1 I also tried one of the answers below to use test.dependsOn and the tests run, but the emma plugin reported the following: build/classes/test', not found

+4
source share
1 answer

1. and 2. just add classes to the compilation test class. This does not affect which tests will be performed.

3. This is the wrong approach because you should not add sources from project X to project Y.

If you want gradle :SubProjectA:test also execute :SubProjectATest:test , all you have to do is add a task dependency:

SubProjectA / build.gradle:

 test.dependsOn(":subProjectATest:test") 

By the way, what is your motivation for passing tests in a separate project?

+4
source

Source: https://habr.com/ru/post/1389309/


All Articles