Question

How to test a void method i.e. method that doesn't return anything in JMock?

Was it helpful?

Solution

To test a method that doesn't return anything, regardless of the testing or mocking framework you're using, you test the effect of a call to the method.

With JMock that likely means that you create a mock of something the code you're testing should call, set things up so that your mock is used instead of a real object, and set and verify expectations for calls to that mock.

I might be able to get more specific if you can add specifics to your question.

OTHER TIPS

void methods generally make some changes in the value of the fields of the class. If the field of the class is not private then you can access it in your test class after calling the void method in your test method to assert if you are getting the expected value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top