문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

Make sure that you are testing every possible combination?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top