Chapter 5. Test coverage and development

 

I don’t think anybody tests enough of anything.

James Gosling

This chapter covers

  • Measuring test coverage
  • Writing testable code
  • Practicing test-driven development

In the previous chapters, we introduced testing software and started exploring testing with JUnit. We also presented various test methodologies.

Now that we’re writing test cases, it’s time to measure how good these tests are by using a test coverage tool to report what code is exercised by the tests and what code is not. We also discuss how to write code that’s easy to test. We finish by looking at test-driven development (TDD).

5.1. Measuring test coverage

Writing unit tests gives you the confidence to change and refactor an application. As you make changes, you run tests, which gives you immediate feedback on new features under test and whether your changes break existing tests. The issue is that these changes may still break existing untested functionality.

In order to resolve this issue, we need to know precisely what code runs when you or the build invokes tests. Ideally, our tests should cover 100 percent of our application code. Let’s look in more detail at what benefits test coverage provides.

5.1.1. Introduction to test coverage

5.2. Writing testable code

 
 

5.3. Test-driven development

 
 
 

5.4. Testing in the development cycle

 

5.5. Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest