• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Mockito and PowerMockito

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rishi Chopra
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 6212
502
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kenneth A. Kousen
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
bacon. tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic