当JaCoCo确定没有值得运行的测试时,Ant构建会不必要地失败

WW.*_*WW. 6 ant testng jacoco

对于持续集成构建,我们使用JcCoCo来最小化要运行的测试数量.但是,在某些提交中,它确定没有值得运行的测试.例如,如果只更改了图像.

以下是来自以下内容的摘录build.xml:

<fileset id="int.tests" dir="${build.inttest.source}/java">
  <include name="**/*Test.java"/>
</fileset>

<taskdef name="testng" classname="org.testng.TestNGAntTask"
  classpath="${build.jars.test}/testng.jar"/>

<jacoco:coverage destfile="./inttest-jacoco.exec">
    <testng outputDir="./reports/intTest" failureproperty="testNGFailed" haltonfailure="false"
      verbose="2" workingDir="${build.dir}" classfilesetref="int.tests">
      <classpath>
        <path refid="build.inttest.classpath"/>
      </classpath>
    </testng>
</jacoco:coverage>
Run Code Online (Sandbox Code Playgroud)

如果未运行任何测试,testNGFailed则将property 设置为true,然后构建将失败.

此方案中的日志记录如下所示:

13:16:49,116 INFO  -    [testng] ===============================================
13:16:49,116 INFO  -    [testng] Ant suite
13:16:49,116 INFO  -    [testng] Total tests run: 0, Failures: 0, Skips: 0
13:16:49,116 INFO  -    [testng] ===============================================
13:16:49,116 INFO  - 
13:16:49,191 WARN  -    [testng] [TestNG] No tests found. Nothing was run
Run Code Online (Sandbox Code Playgroud)

如果没有要运行的测试,我怎样才能使构建通过,但是当任何测试失败时如何失败?

我可以让Jacoco始终至少进行一次测试吗?

我可以让TestNG仅在测试失败时设置失败属性吗?

God*_*din 0

首先 - JaCoCo 不执行你的测试!测试由 TestNG 或 JUnit 或任何测试框架执行 - JaCoCo 只是从该执行中收集覆盖率信息。

根据http://testng.org/doc/ant.html

classfilesetref - 对包含要运行的测试的 ResourceCollection 的引用

而在您的情况下,它指向包含文件的目录.java,因此 TestNG 找不到测试似乎是合乎逻辑的。