Examine Branch Test Coverage (Activity)

From Foss2Serve
(Difference between revisions)
Jump to: navigation, search
m (Additional Information:)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
{| border="1"
+
 
|-
+
{{Learning Activity Overview
|'''Title''' || 
+
|title=
 
Branch Test Coverage
 
Branch Test Coverage
|-   
+
|overview=
|'''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=
|'''Prerequisite Knowledge''' ||
+
* [[:Category:Google Test|Google Test]] must be installed (as instructed in [[Unit Test With GoogleTest Activity]])
GoogleTest needed to have been installed (as instructed in [[Unit Test With GoogleTest Activity]]), and intermediate C++ and git expertise is needed.
+
* Intermediate C++ and git expertise is needed.
|-
+
|objectives=
|'''Learning Objectives''' ||
+
* Examine the branch coverage of unit tests on a simple C++ class to discover and fix errors.
Participants should 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 ===
  
=== Additional Information: ===
+
{{Learning Activity Info
{| border="1"
+
|acm unit=
|-
+
Software Engineering / SE Software Verification Validation
|'''Knowledge Area/Knowledge Unit''' || 
+
|acm topic=
Software Engineering
+
|-
+
|'''Topic''' || 
+
 
Unit Testing, Test Coverage, Branch Coverage
 
Unit Testing, Test Coverage, Branch Coverage
|-
+
|difficulty=
|'''Level of Difficulty''' || 
+
|time=
Intermediate expertise of C++ and imperative programming
+
* 20-30 minutes to comprehend the branch coverage results, identify the error it exposes, and correct the solution.
|-
+
* 15-20 minutes to discuss.
|'''Estimated Time to Completion''' ||
+
|environment=
Comprehending the branch coverage results, identifying the error it exposes, and correcting the solution should take between 20-30 minutes. Discussion should take 15-20 minutes for a total of up to 50 minutes.
+
* Must have completed [Unit Test With GoogleTest Activity] installation process
|-
+
|author=
|'''Materials/Environment''' ||
+
Need to have completed [Unit Test With GoogleTest Activity] installation process
+
|-
+
|'''Author''' || 
+
 
Kevin Buffardi
 
Kevin Buffardi
|-
+
|source=
|'''Source''' ||
+
|license=
Kevin Buffardi
+
{{License CC BY SA}}
|-
+
}}
|'''License''' ||
+
Licensed CC BY-SA 4.0
+
|}
+
 
+
 
+
--------------------
+
This work is licensed under a
+
[http://creativecommons.org/licenses/by-sa/4.0/ Creative Commons Attribution-ShareAlike 4.0 International License]
+
  
[[File:CC_license.png]]
 
  
[[Category: Learning_Activity]]
+
[[Category:Learning Activity]]
[[Category: Quality_and_Testing]]
+
[[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:
  • Examine the branch coverage of unit tests on a simple C++ class to discover and fix errors.
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 within Field.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 up Field.cpp.gcov in your editor. Find that function and look at the gcov analysis of it. You should see some lines that look like:


branch 0 taken 99%
What does the branch number correspond to? What do you think "taken" percentage refers to?

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 your Field.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
  • 20-30 minutes to comprehend the branch coverage results, identify the error it exposes, and correct the solution.
  • 15-20 minutes to discuss.
Environment /
Materials
  • Must have completed [Unit Test With GoogleTest Activity] installation process
Author(s)

Kevin Buffardi

Source
License

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License

CC license.png

Personal tools
Namespaces
Variants
Actions
Events
Learning Resources
HFOSS Projects
Evaluation
Navigation
Toolbox