1
votes

How to mock a class which has a constructor with parameter of mock object using JMock ?

I need to cover the below line of code in my method using JMock.

Search search = Search(request);

In Unit test method I created mock object for request, but I am not able to mock Search because Search has constructor with parameter of mock object request (here I mocked request)

Any help is highly appreciated.

1

1 Answers

0
votes

How would you mock it if it had no constructor? Your problem might be lack of dependency injection. The Search object could be a parameter into the method you call in your test or a field on the class you are testing. On the other hand, if this Search class is a simple bean or helper class you might not need to mock it.

So, in order to help more we need to know more about the code you are testing and more about the Search class.