3 Structural testing and code coverage

 

This chapter covers

  • Creating test cases based on the code structure
  • Combining structural testing and specification-based testing
  • Using code coverage properly
  • Why some developers (wrongly) dislike code coverage

In the previous chapter, we discussed using software requirements as the main element to guide the testing. Once specification-based testing is done, the next step is to augment the test suite with the help of the source code. There are several reasons to do so.

First, you may have forgotten a partition or two when analyzing the requirements, and you may notice that while looking at the source code. Second, when implementing code, you take advantage of language constructs, algorithms, and data structures that are not explicit in the documentation. Implementation-specific details should also be exercised to increase the likelihood of ensuring the program’s full correctness.

In this chapter, we learn how to systematically reflect on the source code, see what is being exercised by the test suite we derived with the help of the specification, and what remains to be tested. Using the structure of the source code to guide testing is also known as structural testing. Understanding structural testing techniques means understanding the coverage criteria. The remainder of this chapter explores using code coverage information to gain more confidence that the program works as expected.

3.1 Code coverage, the right way

 
 

3.2 Structural testing in a nutshell

 
 

3.3 Code coverage criteria

 

3.3.1 Line coverage

 
 

3.3.2 Branch coverage

 

3.3.3 Condition + branch coverage

 
 
 
 

3.3.4 Path coverage

 
 

3.4 Complex conditions and the MC/DC coverage criterion

 
 
 

3.4.1 An abstract example

 
 
 

3.4.2 Creating a test suite that achieves MC/DC

 
 
 
 

3.5 Handling loops and similar constructs

 
 
 

3.6 Criteria subsumption, and choosing a criterion

 
 
 

3.7 Specification-based and structural testing: A running example

 
 
 
 
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