r/learnjava • u/gunterspace • Aug 25 '20
What are some good resources to learn testing with JUnit and Mockito?
I would like to learn more about unit testing, theory and best practices with some practical examples on JUnit and Mockito. I've found some tutorials in the internet, but they don't usually dive too deep. Is there any books or online course I could use as a reference and to learn the basics but with some fundamentals?
Thank's!
1
u/Xermal Aug 25 '20
RemindMe!
2
u/RemindMeBot Aug 26 '20 edited Aug 26 '20
Defaulted to one day.
I will be messaging you on 2020-08-26 23:43:43 UTC to remind you of this link
2 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback
0
0
14
0
u/fustup Aug 26 '20
I think the best way to write a test and learn about Mockito is to "just do it". Sounds stupid, but let me explain:
You should have a clear intention of what exactly your test is: precondition, execution, assertion.
You should write the test as simple and "as prosa-like" as you can do.
And after that you"wire it up", write the mocks you need, the methods, the what have you.
As for best practices: if you do more than just basic mocking be wary. Argument Captors are awesome, maybe the odd method stub returning the only parameter as a result. But that might already be a code smell.
How to write good mocks? Don't 😁(do, of course, but within strict limits)