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

なぜこの問題を解決したのかわかりません。ただし、問題はディレクトリの場所でした。ディレクトリの場所には、他の言語があってはなりません。たとえば、このxmlを実行します

C://

その後はうまくいきますが、

C://한국어//テスト

それではうまく動かない。

于 2016-12-06T02:14:43.787 に答える