Gradle和JaCoCo:来自单独子项目的仪器类

我有一个遗留应用程序,它有一个与应用程序模块分开的unit testing模块。 我正在将项目转换为使用Gradle,结构如下所示:

/root /module1 /module2 ... /moduleN /test 

其中测试模块执行module1到moduleN的测试(并依赖于它们)。 我知道这不是一个很好的做法,因为它有点挫败了unit testing的目的,但众所周知,遗留代码总是令人头疼。

所以在我开始重构代码之前,每个模块都有自己的unit testing(这意味着以合理的方式拆卸测试模块,即大量工作)我想找到一个临时解决方案来获得正确的代码覆盖率,即,让JaCoCo设备来自module1,…,moduleN的所有类,而不仅仅是模块测试。

有没有办法告诉JaCoCo从其他模块中检测类?

要在“test”项目中包含子项目“module *”的覆盖率结果,您可能希望在测试项目的build.gradle中尝试这样的事情:

 // [EDIT] - 'afterEvaluate' NOK, use 'gradle.projectsEvaluated' instead (see comments) // afterEvaluate { gradle.projectsEvaluated { // include src from all dependent projects (compile dependency) in JaCoCo test report jacocoTestReport { // get all projects we have a (compile) dependency on def projs = configurations.compile.getAllDependencies().withType(ProjectDependency).collect{it.getDependencyProject()} projs.each { additionalSourceDirs files(it.sourceSets.main.java.srcDirs) additionalClassDirs files(it.sourceSets.main.output) } } }