13 Testing fundamentals

 

This chapter covers

  • Why we test
  • How we test
  • Test-driven development
  • Test doubles
  • From JUnit 4 to 5

Recent years in programming have seen a growing acceptance of automated testing as an expected part of the development process. Tests are run both locally by developers and in build and continuous integration environments to ensure our systems are behaving. Along with that has come an explosion of different tools, approaches, and philosophies.

As with any technology, there are no silver bullets—no approach to testing will cover every possible situation. Given this, it’s important to understand why you are testing so that you can determine best how to test.

13.1 Why we test

In fact, that word test hides a multitude of possible reasons we’re examining our code’s behavior. A non-exhaustive (and occasionally overlapping) list to consider follows:

13.2 How we test

13.3 Test-driven development

13.3.1 TDD in a nutshell

13.3.2 A TDD example with a single use case

13.4 Test doubles

13.4.1 Dummy object

13.4.2 Stub object

13.4.3 Fake object

13.4.4 Mock object

13.4.5 Problems with mocking

13.5 From JUnit 4 to 5

Summary

sitemap