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.
Junit: best way to test return statement
-
26-06-2022 - |
문제
I am using Junit 4 and I have run into a little problem that I don't really know how to fix.
I have the following statement:
public boolean foo(int someId) {
//bla bla
return updatedLines != 0; //Returns true or false
}
or this:
public boolean foo(int someId){
//bla bla
return (someField.equalsIgnoreCase("value") && someValue > 0);
}
Now my question is: how can I test my return results properly? Now I just check what my method returns (true or false) but my return line isn't covered according to Emma.
해결책
다른 팁
Make sure that you are testing every possible combination?
제휴하지 않습니다 StackOverflow