Answers

Question and Answer:

  Home  JUnit

⟩ How Do You Test a Method That Does not Return Anything?

You need to follow the logic below to answer this question:

* If a method is not returning anything through the "return" statement (void method), it may return data through its arguments. In this case, you can test the data returned in any argument.

* Else if a method is not returning any data through its arguments, it may change values of its instance variables. In this case, you can test changes of any instance variables.

* Else if a method is not changing any instance variable, it may change values of its class variables. In this case, you can test changes of any class variables.

* Else if a method is not changing any class variable, it may change external resources. In this case, you can test changes of any external resources.

* Else if a method is not changing any external resources, it may just doing nothing but holding the thread in a waiting status. In this case, you can test this waiting condition.

* Else if a method is not holding the thread in waiting status, then this method is really doing nothing. In this case, there is no need to test this method. :-)

 124 views

More Questions for you: