Chapter 10. Best Practices

"It is insanity to keep doing things the same way and expect things to improve."

—Anonymous

Writing clean, readable, and maintainable JUnit test cases, just like writing clean code, is an art. A well-written unit test can prevent maintenance nightmare and acts as a system documentation; however, if not used carefully, it can produce meaningless boilerplate test cases. Mistakes are part of the learning process as long as you aren't making them repeatedly. JUnit is not rocket science, so we can practice, follow guidelines, and learn from others to make it perfect.

This chapter covers JUnit guidelines and best practices. The following categories are covered in depth:

  • Writing meaningful tests
  • Test automation
  • Test configuration ...

Get Mastering Unit Testing Using Mockito and JUnit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.