【问题标题】:Ant & JUnit & Jacoco Coverage ErrorAnt & JUnit & Jacoco 覆盖错误
【发布时间】:2017-04-19 12:16:52
【问题描述】:

我想在带有“Junit”的“Ant”构建中使用“Jacoco”。但是,我使用简单的代码进行测试,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() ;
}
}

感谢您的帮助!

【问题讨论】:

    标签: java junit ant jacoco jacoco-maven-plugin


    【解决方案1】:

    我不知道我为什么要解决这个问题。 但是,问题在于目录的位置。 在目录位置的方式上,不应该有任何其他语言。 例如,我在

    上运行这个xml

    C://

    然后它运行良好, 不过

    C://한국어//测试

    然后运行不好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-20
      • 2019-09-14
      • 1970-01-01
      相关资源
      最近更新 更多