What is Code Coverage
Code Coverage is an important measurement in Software Quality Engineering. While Software testing ensures correctness of the applications, a metric is required to track the What is Code Coverage Code Coverage is an important measurement in Software Quality Engineering. While Software testing ensures correctness of the applications, a metric is required to track the completeness and effectiveness of the testing undertaken. Code Coverage helps achieve reliable quality through identifying untested areas of the application.
Why Code Coverage
Software testing is a challenging function. The testers need to ensure complete functional and non-functional correctness of the product. Considering the complex workflows and use cases of modern day applications, the number of unique cases that the software can be used often run into millions, which is not feasible to be covered under testing exercise. The testers thus need to
– While Planning Tests
o Ensure covering all workflows in terms of decision trees in the code
o Ensure covering all data values – by identifying patterns rather covering millions of values
– While testing
o Ensuring the testing is completely exercising the whole application with planned and exploratory tests.
At the end of testing, the decision to stop testing and release the product still remains subjective, based on the presence or absence of bugs, inflow of new bugs, success rate of each test cycle, confidence rating of the testers or users, etc. Whereas the definitive metric of quantifying how much of the application was really tested, is missed.
Code Coverage is measured as quantification of application code exercised by the testing activities. Code Coverage can be measured at various levels – in terms of programming language constructs – Packages, Classes, Methods, Branches or in terms of physical artifacts – Folders, Files and Lines. For Eg. A Line Coverage metric of 67% means the testing exercised 67% of all executable statements of the application. A Code Coverage metric usually is accompanied by Code Coverage Analysis Report – which helps identify the un-tested part of the application code, thereby giving the testers early inputs for complete testing.
Benefits of Code Coverage
- Objective Indicator of Test Coverage of application code
- Pointers to uncovered Packages / Classes / Methods / Branches
- Pointers to uncovered Folders / Files / Lines
- Drill down to untested part of source code and devise new tests
- Early Indicator for Testing Quality and Fixing it by adding new tests.
- Remove redundancy in testing
- Increased Confidence for Releases
Test Your Test
Typical Emotional Storyboard
- Write Some code! Happy!
- Does it work? Sad!
- Write some test! Happy!
- Do they really test the code? Sad!
- Measure the Code Coverage! Happy!
- Shows Which line of code are executed
- How much of your code is covered by your tests?
- Your tests test your product
- Coverage testing tests your tests
- Coverage Ideal
- Not Always possible
- Can be expensive to achieve
- Design for testability
Good: Write more tests
Only way to truly increase code coverage
Excluding Code to boost Coverage
Types of Coverage
- Statement Coverage
- Branch Coverage
- Path Coverage
- Loop Path Coverage
- Data – driven Code
- Complex Conditionals
- Hidden Branches
How; – Coverage Tools
- What is Xray in Jira? - April 9, 2021
- How to build jobs in jenkins when a change is pushed to Bitbucket - April 8, 2021
- How to trigger a jenkins job when code is pushed to github using “GitHub hook trigger for GITScm polling” - April 8, 2021