Pitest-突变测试失败 - 否定条件→幸存

发布于 2025-02-09 01:11:09 字数 461 浏览 2 评论 0原文

我在我的代码中添加了一个条件运算符,例如:

String test;//assigned with some value
result = test != null ? test : "";

这在突变测试中失败,原因是否定的条件→幸存

我添加了很少的单位测试用例,可以用“”分配值null“ value”喜欢

asserThat(testValue.equals(""));

,但没有什么可以为此提供解决方案。

我可以从任何人那里得到有关此特定流程的突变覆盖范围的帮助吗?

I added a conditional operator in my code like:

String test;//assigned with some value
result = test != null ? test : "";

This fails in mutation testing with the reason of negated conditional → SURVIVED

I added few unit test cases to assign the value with "" , null, "value" like

asserThat(testValue.equals(""));

But nothing is giving the solution for this.

Can I get help from anyone about the mutation coverage for this specific flow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水染的天色ゝ 2025-02-16 01:11:09
assertThat(testValue.equals(""));

不是功能性的断言。假设您正在使用assertj,则应该这样做。

assertThat(testValue).isEqualTo("");

目前尚不清楚您的代码和测试从您发布的小片段中的外观。但是被否定的有条件在以下代码中被杀死,并在提供的测试中被杀死。

public class Foo {
    public static String foo(String test) {
        String result = test != null ? test : "";
        return result;
    }
}
class FooTest {
    @Test
    void convertsNullToEmptyString() {
        assertEquals("", Foo.foo(null));
    }

    @Test
    void returnsNonNullValues() {
        assertEquals("hello", Foo.foo("hello"));
    }
}
assertThat(testValue.equals(""));

Is not a functioning assertion. Assuming you are using AssertJ, this should be.

assertThat(testValue).isEqualTo("");

It is not entirely clear what your code and tests look like from the small snippets you have posted. But the negated conditional is killed in the following code with the supplied test.

public class Foo {
    public static String foo(String test) {
        String result = test != null ? test : "";
        return result;
    }
}
class FooTest {
    @Test
    void convertsNullToEmptyString() {
        assertEquals("", Foo.foo(null));
    }

    @Test
    void returnsNonNullValues() {
        assertEquals("hello", Foo.foo("hello"));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文