Mockito and PowerMockito
posted 2 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I have personally used mockito a lot for various projects, I have lately joined a company where we have this big monolith and the test suite I have see uses lot of PowerMockito ( probably around mockito statics and usage of whenNew)
Can you suggest if your book or generally there is a way to remove these anti patterns and thus use of powermockito from codebase gradually ?
Thanks
Rishi
I have personally used mockito a lot for various projects, I have lately joined a company where we have this big monolith and the test suite I have see uses lot of PowerMockito ( probably around mockito statics and usage of whenNew)
Can you suggest if your book or generally there is a way to remove these anti patterns and thus use of powermockito from codebase gradually ?
Thanks
Rishi
Life is Beautiful Learn to See it.........
posted 2 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think by PowerMockito you actually mean PowerMock, which is an alternative mocking and stubbing framework unrelated to Mockito. If you're asking how to remove mocks and stubs from your code base entirely, I think you're missing the benefits of using a framework to autogenerate fake objects in useful situations, several of which I covered in the two videos I linked to in another recent post.
My goal is more to show people how to use Mockito effectively.
Nevertheless, I wish you good luck in your testing.
My goal is more to show people how to use Mockito effectively.
Nevertheless, I wish you good luck in your testing.
Kenneth A. Kousen, Ph.D. (assorted certs),
President, Kousen IT, Inc, http://www.kousenit.com
Rishi Chopra
Ranch Hand
Posts: 120
posted 2 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Thanks for your reply
Not really looking to remove mocks and stubs but use of powermock to mock statics, test private methods seems to be anti pattern used in a monolith at my work place.
I beleive these are not good patterns so just thought to see if mockito can help ease the pain and help us with removing these anti patterns in the codebase from testing perspective
Thanks
Rishi
Thanks for your reply
Not really looking to remove mocks and stubs but use of powermock to mock statics, test private methods seems to be anti pattern used in a monolith at my work place.
I beleive these are not good patterns so just thought to see if mockito can help ease the pain and help us with removing these anti patterns in the codebase from testing perspective
Thanks
Rishi
Life is Beautiful Learn to See it.........
posted 2 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you're looking for a title to teach you ways in which you can make your code more testable I highly recommend "working effectively with legacy code" by Michael Feathers.
Tim Driven Development | Test until the fear goes away
Kenneth A. Kousen
gunslinger & author
Posts: 169
16
posted 2 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
For the record, Mockito can mock static methods now. It still doesn't mock anything private, because of the basic philosophical objection that the class you're testing shouldn't even be aware that the dependency it needs has private methods. If it does, it certainly shouldn't be calling them.
Over the years, Mockito has added many features it didn't originally agree with, like mocking constructors, static methods, and final methods and classes. I don't see it ever mocking private methods.
I'm still not sure how to answer a question that comes down to, how can I remove these tests that I don't agree with in my code? That's not really the job of an API. That's talking to the other developers about your objections and making a plan as a team on how to handle them.
Over the years, Mockito has added many features it didn't originally agree with, like mocking constructors, static methods, and final methods and classes. I don't see it ever mocking private methods.
I'm still not sure how to answer a question that comes down to, how can I remove these tests that I don't agree with in my code? That's not really the job of an API. That's talking to the other developers about your objections and making a plan as a team on how to handle them.
Kenneth A. Kousen, Ph.D. (assorted certs),
President, Kousen IT, Inc, http://www.kousenit.com
| bacon. tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









