2

カバーされている 100% のコードには達していませんが、そうしたいと思っています。100% 緑色に見えない限り、何をテストするのを忘れて、ツールに基づいてばかげたことを見つけるためだけに探しに行くのだろうかと思います。それから後で私は忘れて、すすぎ/繰り返す必要があります.

例外のため、すべてのパスが testThrow でカバーされますが、実行としてカウントされません。

とらえどころのない 100% 緑に覆われているように見えるように書き直す方法はありますか。

public class Dummy {
    public void testThrow() throws Exception {
        throwException();       // This line is red and is seen as not covered.
    }

    private void throwException() throws Exception {
        throw new Exception();
    }
}

public class DummyTest() {
    @Test
    public void testThrow() throws Exception {
        new Dummy().testThrow();
    }
}

@Test(expected=Exception.class) を追加しましたが、行はまだ赤です。

私も試しました:

public void testThrow() throws Exception {
    try {
        throwException();       // This line is STILL red
    }
    catch(Exception e) {
        throw e;                // This line becomes green (as expected)
    }
}                               // This line is now also red
4

1 に答える 1