I want to mock a class using the Mockito framework, that has a couple of constructor arguments.
How would i go about passing those constructor arguments without generating setters for the private member variables ?
Thanks
You said you want to mock some but not all of the methods. I'm not sure why you'd want to do this - if your class is a collaborator, then it would make sense to mock the whole class. Or if it's the SUT, you probably don't want to mock it at all.
It's possible that what you're looking for is a spy, rather than a mock. If you decide to use a spy, you'll make it from a real object, which has already been constructed using whatever arguments you need it to be constructed from.
But before you consider using a spy, I urge you to think more carefully about exactly what it is that you're testing, and why you think you need to replace some of your methods with mock implementations, but not others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With