0

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

Anand
  • 20,708
  • 48
  • 131
  • 198
  • Are you trying to test the effect of a void method? Or are you trying to verify whether or not it was called? It is not obvious why you are using JMock here. – Kkkev Jul 24 '12 at 17:39

2 Answers2

1

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.

Don Roby
  • 40,677
  • 6
  • 91
  • 113
0

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.

xpioneer
  • 3,075
  • 2
  • 16
  • 18