0

我正在使用 Junit 4,但遇到了一个我真的不知道如何解决的小问题。

我有以下声明:

public boolean foo(int someId) {
   //bla bla
   return updatedLines != 0; //Returns true or false
}

或这个:

public boolean foo(int someId){
   //bla bla
   return (someField.equalsIgnoreCase("value") && someValue > 0);
}

现在我的问题是:如何正确测试我的退货结果?现在我只检查我的方法返回的内容(真或假),但根据 Emma,我的返回线没有被覆盖。

4

2 回答 2

1

You have to make sure that all possible outcomes are tested. So for the first statement you have at least two testcases: one where true is returned, the other where false is returned. If there are more branches is your return statement, you need to make sure that all are tested.

于 2013-08-29T09:04:19.767 回答
1

确保您正在测试所有可能的组合?

于 2013-08-29T02:59:04.773 回答