Gradle - 如何从不同的gradle项目运行测试并获取覆盖数据 [英] Gradle - how to run the tests from a different gradle project and still get coverage data

查看:162
本文介绍了Gradle - 如何从不同的gradle项目运行测试并获取覆盖数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何从一个不同的gradle项目运行测试,仍然可以获得emma覆盖率报告数据吗?

这是我目前的layout:

 根/ 
settings.gradle(没有显式的build.gradle - 只是定义了所有子项目)
SubProjectA /
build.gradle
src /(所有真正的源代码在这里)
SubProjectATest /
build.gradle
src /(所有测试代码在这里)
SubProjectB /(类似于A的结构)
SubProjectBTest /(与ATest类似的结构)

我目前正在使用emma插件,并且我希望构建 SubProjectA 并从 SubProjectA 栏内的 SubProjectATest 中运行所有测试。 / em>的。



以下是我在SubProjectA的build.gradle中尝试的一些内容:


  1. testCompile project(':SubProjectATest')。sourceSets.test.classes 正如本文所建议的那样),但是我得到一个错误找不到项目的属性'sourceSets'

  2. 直接使用 testCompile项目(':SubProjectATest'),但是我得到 .. SubProjectA / build / classes / test ',找不到和跳过任务':SubProjectA:compileTestJava',因为它没有源文件。

  3. 简单地添加如下的sourceSet:

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


是唯一可行的选项,但这样做看起来很sl sl。有谁知道如何使用项目依赖关系来做到这一点?



更新#1
我也尝试了下面的答案之一来使用test.dependsOn和测试运行,但emma插件报告如下: build / classes / test',not found

解决方案

1。和2.只需将类添加到测试编译类路径。这对要执行的测试没有任何影响。



3。如果你想要的是 gradle:SubProjectA:test / code>还会执行:SubProjectATest:test ,您只需添加一个任务依赖关系

$
$ b

SubProjectA / build.gradle:

  test.dependsOn(:subProjectATest:test )

顺便说一下,您将测试放在单独项目中的动机是什么?


Does anyone know how to run the tests from a different 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 within the build.gradle of SubProjectA.

Here are some things I tried inside the build.gradle of SubProjectA

  1. testCompile project(':SubProjectATest').sourceSets.test.classes (as suggested by this article), but I got an error "Could not find property 'sourceSets' on project"
  2. Just the straight-up testCompile project(':SubProjectATest'), but then I get "..SubProjectA/build/classes/test', not found" and also "Skipping task ':SubProjectA:compileTestJava' as it has no source files."
  3. Simply adding a sourceSet like the following:

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

Adding the source set in (option 3) is the only option that worked, but it seems sloppy to do it this way. 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 do run, but the emma plugin reported the following: build/classes/test', not found

解决方案

1. and 2. just add classes to the test compile class path. This doesn't have any effect on which tests are going to be executed.

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

If what you want is that gradle :SubProjectA:test also executes :SubProjectATest:test, all you need to do is to add a task dependency:

SubProjectA/build.gradle:

test.dependsOn(":subProjectATest:test")

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

这篇关于Gradle - 如何从不同的gradle项目运行测试并获取覆盖数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆