java - 是否有某种 'assertion' 覆盖工具(用于 Java)?

标签 java code-coverage

在这个问题被标记为重复之前,请阅读它。 ;) 已经有几个关于覆盖工具等的问题,但这与通常的问题有点不同(我希望如此)。

根据 wikipedia有几种不同类型的“覆盖范围”变体会影响术语“覆盖范围”的几个不同方面。

举个例子:

public class Dummy {
    public int a = 0;
    public int b = 0;
    public int c = 0;

    public void doSomething() {
        a += 5;

        b += 5;

        c = b + 5;
    }
}

public class DummyTest {

    @Test
    public void testDoSomething() {
        Dummy dummy = new Dummy();

        dummy.doSomething();

        assertEquals( 10, dummy.c );
    }
}

如您所见,测试将覆盖 100% 的行,对字段“c”的值的断言将覆盖该字段并间接覆盖字段“b”,但是字段上没有断言覆盖'一种'。 这意味着测试覆盖了 100% 的代码行并确保 c 包含预期值并且很可能 b 也包含正确的值,但是 a 根本没有断言并且可能是一个完全错误的值。

那么...现在的问题是:是否有一种工具能够分析 (java) 代码并创建关于哪些字段/变量/任何未被(直接和/或间接)断言覆盖的报告?

(好的,当使用 getter 而不是公共(public)字段时,您会看到没有调用 getA(),但这不是我想听到的答案;))

最佳答案

As you can see, the test will have a coverage of 100% lines, the assertion on the value of field 'c' will cover this field and indirectly also cover field 'b', however there is no assertion coverage on field 'a'. This means that the test covers 100% of the code lines and assures that c contains the expected value and most probably also b contains the correct one, however a is not asserted at all and may a completely wrong value.

不幸的是,“覆盖”对不同的人有不同的含义……这个测试确实练习 100% 的代码行,但它没有测试所有的代码行.

mutation testing 处理的很好.

看看Jester ,它使用变异测试来报告代码覆盖率。

关于java - 是否有某种 'assertion' 覆盖工具(用于 Java)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5960859/

相关文章:

c++ - gcovr - 在 xml 覆盖范围 Cobertura 报告中是否存在损坏文件名的已知问题?

testing - 如何重写此 select 语句以保证 100% 的测试覆盖率?

c++ - 在 C++ 代码中查找未使用的函数以测试覆盖率

Java - 在程序中创建新的文件扩展名

java - 将 JFrame 与 pack() 结合使用

java - Gradle srcDirs 路径

testing - grails代码覆盖无法访问方法

c++ - GCOV-在其他文件夹中生成的gcda文件

java - 如何指定字体属性的通用映射?

java - 使用不同对象的同步块(synchronized block)