r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

Show parent comments

1

u/FrozenST3 Jun 02 '24

True, but a bad test is a bad test whether using a mocking framework or not.  You can test request accuracy using @Captor. A lot of the criticism I see stem more from misuse rather than a problem with the frameworks themselves.

0

u/DelayLucky Jun 02 '24

That misses the point.

Whatever assertion your test performs on the request is your assumption. You still don't know if your assumption is valid. If we can assume you know perfectly, you wouldn't have needed to test.

1

u/FrozenST3 Jun 02 '24

Fair however my response was using the assumption that the service being mocked is already well tested. I agree that mocking untrustworthy code is best avoided but I assumed that's common sense. Edit to add: your tests don't exist only for you to trust what you've done, but also to safeguard future changes where bugs are produced do to poor assumptions 

1

u/DelayLucky Jun 02 '24

The service tested its own implementation. It cannot test that you've called it correctly.

You have written the calling code according to the best of your knowledge. But you don't know if your knowledge is correct.

Even if you manually test them once, either code change at your side or change in the service can cause regression such that the interaction suddenly becomes no longer valid.

→ More replies (2)