1

我想在带有“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() ;
}
}

谢谢您的帮助!

4

1 回答 1

0

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

C://

然后它运行良好,但是

C://한국어//测试

然后它运行不好。

于 2016-12-06T02:14:43.787 回答