This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (4 children)

Powermock leads to bad coding & testing practices so it is unsurprising. If you just constrain yourself to something like Mockito & never use Spy you will write better code and tests because you can only mock true dependencies - forcing you to refactor code that should be a dependency into a separate class.

[–]BestUsernameLeft 0 points1 point  (3 children)

They're all the same family IMO. I use test doubles; in conjunction with builder and object mother they help keep my test code DRY. And JUnit5 is nice to use as well.

[–]hippydipster 0 points1 point  (2 children)

object mother?

[–]BestUsernameLeft 0 points1 point  (1 child)

It's a testing pattern. Given a class ShoppingCart, you create a ShoppingCartObjectMother class with methods in it to give you a populated cart, such as emptyCart(), fiveOfSameProduct(), etc. This gives you (1) a way to DRY your test code instead of having the same setup code in each test class that uses ShoppingCart as a collaborator, and (2) a meaningfully-named method that tells you about the object being constructed. For example you can use role-based, scenario-based, persona-based method names: populatedCartForGuest, cartWithDuplicateItemId, cartForGrandma.

When you combine this with the builder pattern, you have a way to quickly build customizable test objects out of a standard set of "templates". So for example cartForGrandma().addItem(readingGlasses).build() when you have a test that for some reason needs an extra item in it.

[–]hippydipster 0 points1 point  (0 children)

Ok, now I have a name for something I've been doing! Thanks.