Examine Branch Test Coverage (Activity)
m (→Additional Information:) |
|||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | {| | + | |
− | + | {{Learning Activity Overview | |
− | + | |title= | |
Branch Test Coverage | Branch Test Coverage | ||
− | | | + | |overview= |
− | + | ||
Participants examine branch test coverage to discover potential errors in their code. | Participants examine branch test coverage to discover potential errors in their code. | ||
− | | | + | |prerequisites= |
− | | | + | * [[:Category:Google Test|Google Test]] must be installed (as instructed in [[Unit Test With GoogleTest Activity]]) |
− | + | * Intermediate C++ and git expertise is needed. | |
− | | | + | |objectives= |
− | + | * Examine the branch coverage of unit tests on a simple C++ class to discover and fix errors. | |
− | + | |process skills= | |
− | |} | + | }} |
− | === Directions | + | === Directions === |
− | ==== Instructor | + | ==== Instructor ==== |
*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 | *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 | ||
− | ==== Students | + | ==== Students ==== |
− | *This exercise continues from [[Introduction to Test Driven Development]] | + | * This exercise continues from [[Introduction to Test Driven Development]] |
− | *Fork and clone the upstream repository of [https://github.com/ChicoState/minefield Minefield]. | + | * Fork and clone the upstream repository of [https://github.com/ChicoState/minefield Minefield]. |
− | *Get the updates from the (upstream) Minefield and put it into a new branch called branchcov by using the following commands: | + | * Get the updates from the (upstream) Minefield and put it into a new branch called branchcov by using the following commands: |
<code><br/> | <code><br/> | ||
git remote add upstream https://github.com/ChicoState/minefield.git<br/> | git remote add upstream https://github.com/ChicoState/minefield.git<br/> | ||
Line 30: | Line 29: | ||
This creates the new branch by pulling from the upstream master branch and checks out the new branch locally<br/> | This creates the new branch by pulling from the upstream master branch and checks out the new branch locally<br/> | ||
</code> | </code> | ||
− | *Look over the unit tests for the <code>revealAdjacent()</code> function and see what cases have been handled. Review the function within <code>Field.cpp</code> if you want to see how the solution is implemented. | + | * Look over the unit tests for the <code>revealAdjacent()</code> function and see what cases have been handled. Review the function within <code>Field.cpp</code> if you want to see how the solution is implemented. |
− | *Next, make the project and run the tests using <code>make test</code>. Do the tests pass? How confident are you in the solution? | + | * Next, make the project and run the tests using <code>make test</code>. 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: <code>gcov -b Field.cpp</code>. Note that the <code>-b</code> option is short for: <code>--branch-probabilities</code>. Within the results you should find: | + | * Let's look at how comprehensively we've tested the function. Run the command: <code>gcov -b Field.cpp</code>. Note that the <code>-b</code> option is short for: <code>--branch-probabilities</code>. Within the results you should find: |
<code><br/> | <code><br/> | ||
Line 43: | Line 42: | ||
</code> | </code> | ||
− | *This summarizes the whole file, but we want to concentrate specifically on <code>revealAdjacent()</code> so open up <code>Field.cpp.gcov</code> in your editor. Find that function and look at the gcov analysis of it. You should see some lines that look like: | + | * This summarizes the whole file, but we want to concentrate specifically on <code>revealAdjacent()</code> so open up <code>Field.cpp.gcov</code> in your editor. Find that function and look at the gcov analysis of it. You should see some lines that look like: |
<code><br/> | <code><br/> | ||
Line 52: | Line 51: | ||
'''STOP HERE AND WAIT FOR DISCUSSION''' | '''STOP HERE AND WAIT FOR DISCUSSION''' | ||
− | *After we have refactored the code, you have some updates to retrieve so go to your <code>branchcov</code> branch and fetch from upstream | + | * After we have refactored the code, you have some updates to retrieve so go to your <code>branchcov</code> branch 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 <code>revealAdjacent()</code>. For this exercise, you may disregard the branches in the constructor. Upload your <code>Field.cpp.gcov</code> to complete this assignment. | + | * 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 <code>revealAdjacent()</code>. For this exercise, you may disregard the branches in the constructor. Upload your <code>Field.cpp.gcov</code> to complete this assignment. |
− | === Deliverables | + | === Deliverables === |
Revised code in a C++ program to resolve an error. | Revised code in a C++ program to resolve an error. | ||
− | === Assessment | + | === Assessment === |
Students should look through branch coverage results to see where the logic does not work correctly for all possible cases and correct the problem. | Students should look through branch coverage results to see where the logic does not work correctly for all possible cases and correct the problem. | ||
− | === Comments | + | === Comments === |
− | + | {{Learning Activity Info | |
− | + | |acm unit= | |
− | + | Software Engineering / SE Software Verification Validation | |
− | + | |acm topic= | |
− | Software | + | |
− | | | + | |
− | + | ||
Unit Testing, Test Coverage, Branch Coverage | Unit Testing, Test Coverage, Branch Coverage | ||
− | | | + | |difficulty= |
− | | | + | |time= |
− | + | * 20-30 minutes to comprehend the branch coverage results, identify the error it exposes, and correct the solution. | |
− | + | * 15-20 minutes to discuss. | |
− | + | |environment= | |
− | + | * Must have completed [Unit Test With GoogleTest Activity] installation process | |
− | | | + | |author= |
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
Kevin Buffardi | Kevin Buffardi | ||
− | | | + | |source= |
− | | | + | |license= |
− | + | {{License CC BY SA}} | |
− | + | }} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | [[Category: | + | [[Category:Learning Activity]] |
− | [[Category: | + | [[Category:Quality and Testing]] |
+ | [[Category:Google Test]] | ||
+ | [[Category:CS2]] | ||
+ | [[Category:Good Draft]] |
Latest revision as of 13:33, 8 September 2018
Title |
Branch Test Coverage |
---|---|
Overview |
Participants examine branch test coverage to discover potential errors in their code. |
Prerequisites |
|
Learning Objectives |
After successfully completing this activity, the learner should be able to:
|
Process Skills Practiced |
Directions
Instructor
- 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
Students
- 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 withinField.cpp
if 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-b
option is short for:--branch-probabilities
. Within the results you should find:
File 'Field.cpp'
Lines executed:
Branches executed:
Taken at least once:
No calls
Field.cpp:creating 'Field.cpp.gcov'
- This summarizes the whole file, but we want to concentrate specifically on
revealAdjacent()
so open upField.cpp.gcov
in 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
branchcov
branch 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 yourField.cpp.gcov
to complete this assignment.
Deliverables
Revised code in a C++ program to resolve an error.
Assessment
Students should look through branch coverage results to see where the logic does not work correctly for all possible cases and correct the problem.
Comments
ACM BoK Area & Unit(s) |
Software Engineering / SE Software Verification Validation |
---|---|
ACM BoK Topic(s) |
Unit Testing, Test Coverage, Branch Coverage |
Difficulty | |
Estimated Time to Complete |
|
Environment / Materials |
|
Author(s) |
Kevin Buffardi |
Source | |
License |
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License |