我想在“Ant”构建中使用“Jacoco”和“Junit”。然而,我使用了简单的代码进行测试,Jacoco 没有涵盖任何内容。构建运行良好,执行运行良好,Junit 也向我显示结果,但是,Jacoco 不能。
<target name="cov-test" depends ="build">
<jacoco:coverage>
<junit showoutput="true" printsummary="on" enabletestlistenerevents="true" fork="true">
<classpath path="classes" />
<classpath path="lib/junit.jar" />
<classpath path="lib/hamcrest-core.jar" />
<formatter type="plain" usefile="false" />
<test name="SimpleTest">
</test>
</junit>
</jacoco:coverage>
<jacoco:coverage>
<java classname="SimpleTest" fork="true">
<classpath path="classes" />
<classpath path="lib/junit.jar" />
<classpath path="lib/hamcrest-core.jar" />
</java>
</jacoco:coverage>
</target>
<target name="cov-report" depends="cov-test">
<jacoco:report>
<executiondata>
<fileset file="jacoco.exec" />
</executiondata>
<structure name="SimpleTest">
<classfiles>
<fileset dir="classes" />
</classfiles>
<sourcefiles>
<fileset dir="src" />
</sourcefiles>
</structure>
<html destdir="report" />
</jacoco:report>
</target>
这是我的ant的build.xml,Jacoco向我展示了报告,但是,它从未覆盖任何类文件。均匀,主类不执行。我的简单java测试代码是
public class Simple
{
public Simple() {
}
public int exec(int i) {
if (i > 0)
return i ;
return i * -1 ;
}
}
public class SimpleTest
{
@Test
public void testSimple1() {
Simple s = new Simple() ;
assertTrue(s.exec(-1) == 1) ;
}
@Test
public void testSimple2() {
Simple s = new Simple() ;
assertTrue(s.exec(1) == 1) ;
}
public static void main(String [] args) {
SimpleTest s = new SimpleTest() ;
//s.testSimple1() ;
//s.testSimple2() ;
}
}
感谢您的帮助!
最佳答案
我不知道为什么我解决了这个问题。 然而,问题在于目录的位置。 在目录位置方式上,不应该有任何其他语言。 例如,我运行此 xml
C://
然后就可以正常运行了 然而
C://한국어//测试
那么它就不能很好地运行。
关于java - Ant & JUnit & Jacoco 覆盖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40968589/