1. Knowledge Share on Code Coverage Magus Chen maguschen@hotmail.com http://magustest.com/blog/
2. Agenda What is Code Coverage How it Works Common Mistakes Some Thoughts References 2
3. What is Code Coverage Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. 3
4. What is Code Coverage Statement coverage Decision(Branch) coverage Condition coverage Condition/decision coverage Function coverage http://en.wikipedia.org/wiki/Code_coverage http://www.javaranch.com/journal/2004/01/IntroToCodeCoverage.html http://www.exampler.com/testing-com/writings/coverage-terminology.html 4
5. How does Code Coverage Works Essentially all code coverage tools instrument the code in order to check which parts of the code were executed. When test executed, code coverage tool will collect Usually there are some tools can parse the coverage result data file and generate a report http://www.bullseye.com/paper.html 5
6. Common Mistakes Try to reach 100% coverage Some part of the code is hard to reach Non-critical code should be set low priority Follow the idea of the code The existence code looks good and we get 100% coverage, the problem is that feature cannot be found in the code(never written) Confuse high coverage with high quality The most useful information of code coverage report can tell us is which lines in the application were not being test. 6
7. Some Thoughts Run the test against AUT Check code coverage report and retest Phase I Target on simple feature test Filter current feature related code and indentify the untest code (Line coverage) Add more test case to cover those untest code Phase II Target on most critical feature test Filter current feature related code and indentify the untest code (Branch coverage) Add more test case to fulfill the branch coverage 7
8. References on Tools http://ltp.sourceforge.net/coverage/lcov.php http://gcc.gnu.org/onlinedocs/gcc/Gcov.html http://www.bobah.net/d4d/tools/code-coverage-with-gcov http://www.network-theory.co.uk/docs/gccintro/gccintro_81.html http://open-tube.com/10-code-coverage-tools-c-c 8