Examine Branch Test Coverage (Activity)
Branch Test Coverage
Participants examine branch test coverage to discover potential errors in their code.
|Learning Objectives||After successfully completing this activity, the learner should be able to:
|Process Skills Practiced|
- Pause when most students have reached the intermission (marked below) and explain the gcov results to demonstrate how branch coverage exposes more than line coverage
- This exercise continues from Introduction to Test Driven Development
- Fork and clone the upstream repository of Minefield.
- Get the updates from the (upstream) Minefield and put it into a new branch called branchcov by using the following commands:
git remote add upstream https://github.com/ChicoState/minefield.git
git checkout -b branchcov upstream/master
This creates the new branch by pulling from the upstream master branch and checks out the new branch locally
- Look over the unit tests for the
revealAdjacent()function and see what cases have been handled. Review the function within
Field.cppif you want to see how the solution is implemented.
- Next, make the project and run the tests using
make test. Do the tests pass? How confident are you in the solution?
- Let's look at how comprehensively we've tested the function. Run the command:
gcov -b Field.cpp. Note that the
-boption is short for:
--branch-probabilities. Within the results you should find:
Taken at least once:
- This summarizes the whole file, but we want to concentrate specifically on
revealAdjacent()so open up
Field.cpp.gcovin your editor. Find that function and look at the gcov analysis of it. You should see some lines that look like:
What does the branch number correspond to? What do you think "taken" percentage refers to?
branch 0 taken 99%
STOP HERE AND WAIT FOR DISCUSSION
- After we have refactored the code, you have some updates to retrieve so go to your
branchcovbranch and fetch from upstream
- Now that you have a better understanding of how to read the results of gcov's branch coverage, continue testing until you have tested all the branches for
revealAdjacent(). For this exercise, you may disregard the branches in the constructor. Upload your
Field.cpp.gcovto complete this assignment.
Revised code in a C++ program to resolve an error.
Students should look through branch coverage results to see where the logic does not work correctly for all possible cases and correct the problem.
| ACM Body of Knowledge
Area & Unit(s)
Software Engineering / SE Software Verification Validation
Unit Testing, Test Coverage, Branch Coverage
|Environment / Materials||
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License