Book Image

Mastering Unit Testing Using Mockito and JUnit

By : Sujoy Acharya
Book Image

Mastering Unit Testing Using Mockito and JUnit

By: Sujoy Acharya

Overview of this book

Table of Contents (17 chapters)
Mastering Unit Testing Using Mockito and JUnit
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Configuring tests


This section deals with the test configuration. Unit tests are not testing the system. In TDD, unit tests are written to obtain the following benefits:

  • They drive your design. You write a test, add code to fix the test, refactor code with confidence, and apply the design. This results in a simple, clean, maintainable, loosely coupled, and cohesive design. You write code to satisfy a failing test, so it limits the code you write to only what is needed.

  • The tests provide fast, automated regression for refactoring and enhancing the code.

You should configure your tests to follow the following principles:

  • Unit tests should be executed extremely fast so that they can provide quick feedback. Would you withdraw money from an ATM that takes 10 minutes to dispense money?

  • Tests should be reliable. Tests should fail if the production code is broken. Your tests will be considered unreliable in situations where you break the production logic but the tests pass, or you don't touch the production...