Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock each and every instance of a class

I want to mock my java class in such a ways so that each and every new instance of it should return the mocked response.

like image 866
Parnik Kumar Gaurav Avatar asked Oct 19 '22 01:10

Parnik Kumar Gaurav


1 Answers

There are two mocking libraries which support this: PowerMock (as shown in Matthias' answer), and JMockit.

In the second case, the test only needs to declare a mock field or mock parameter using the @Mocked annotation.

like image 178
Rogério Avatar answered Oct 21 '22 21:10

Rogério