How would you assert code like this? What would be the best approach to do so?
public void doSomething(int myProperty){
if (myProperty == 0) return;
// If myProperty is not zero, do something in the method
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could assert that whatever happens after the
returndoesn’t happen whenmyPropertyis zero.For example, if the method is (pseudo code!)
then your unit test could
myPropertyis set to zero,myOtherPropertyis set to something other than2myOtherPropertyis still set to what it was set to before.