Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test a method with void return type?

How do you write a unit test for a method with void return type?

like image 902
mchicago Avatar asked Feb 11 '11 18:02

mchicago


1 Answers

Assuming the method does something, you can try to sense that something.

That is, suppose it increments a variable that is exposed elsewhere in a property - you can check the value of the property before and after calling the method.

In essence this is checking that the method is working correctly by checking the expected side-effects from it.

like image 141
Oded Avatar answered Oct 03 '22 16:10

Oded