为什么这个语句没有被标记为完全被 elemma 覆盖?

发布于 2024-10-07 17:59:25 字数 474 浏览 0 评论 0原文

我在 Eclipse 中使用 EclEmma(更具体地说,RSA 8)。我的代码中有以下语句:

public static boolean isEmpty(Collection collection) {
    return (collection == null) || collection.isEmpty();
}

并且我有以下测试:

@Test public void isEmpty_nullCase() {
    assertTrue(CollectionUtil.isEmpty(null));
}
@Test public void isEmpty_listCase() {
    assertTrue(CollectionUtil.isEmpty(new ArrayList()));
}

但由于某种原因,该语句显示为黄色。我没有测试哪一部分?

谢谢, 彼得

I am using EclEmma in Eclipse (more specifically, RSA 8). I have the following statement in my code:

public static boolean isEmpty(Collection collection) {
    return (collection == null) || collection.isEmpty();
}

and I have the following tests:

@Test public void isEmpty_nullCase() {
    assertTrue(CollectionUtil.isEmpty(null));
}
@Test public void isEmpty_listCase() {
    assertTrue(CollectionUtil.isEmpty(new ArrayList()));
}

but for some reason, the statement is showing up as yellow. What part of it am I not testing?

Thanks,
Peter

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

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

发布评论

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

评论(2

2024-10-14 17:59:26

如果一个 ArrayList 具有值并且因此不为空呢?

How about an ArrayList that has a value, and is therefore not empty?

青衫儰鉨ミ守葔 2024-10-14 17:59:26

添加以下测试用例:

@Test
public void checkNonNullNonEmpty(){
   Assert.assertFalse(CollectionUtil.isEmpty(new ArrayList<String>(){
    {
      add("blah blah blah....!");
    }
  });
}

您仅测试了真实条件。理想情况下,return (collection == null) || 有 4 种可能的组合集合.isEmpty();
声明。第一个条件可以是 T/F,第二个条件可以是 T/F。所以总共有4种可能性。您只涵盖了 3 个。上述测试用例将涵盖非空非空可能性。

Add the following test case:

@Test
public void checkNonNullNonEmpty(){
   Assert.assertFalse(CollectionUtil.isEmpty(new ArrayList<String>(){
    {
      add("blah blah blah....!");
    }
  });
}

You have only tested true conditions. Ideally there are 4 possible combinations of return (collection == null) || collection.isEmpty();
statement. 1st condition can be T/F and 2nd can be T/F. So totall 4 possibilities. You have covered 3 only. The above test case will cover non null non empty possibility.

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