SlideShare a Scribd company logo
1 of 19
CODE COVERAGE – A DUMP METRIC
For Code Quality Thomas Rothe
Enterprise DevOps Coach
Thomas Rothe
Code Coverage is not a bad metric
- It's just a dump one!
Fixing (and finding) bugs late is costly
Code Coverage
Is a measure used in software testing. It describes the degree to
which the source code of a program has been tested.
https://en.wikipedia.org/wiki/Code_coverage
SourcecodeUnitTestCC
SourcecodeUnitTestCC
The Sneaky Developer The Metric Lovin’ Manager
SourcecodeUnitTestCC
SourcecodeUnitTestCC
Why?
Why do we need Code Coverage
____________________________________________
To Ensure Quality
Minimize Bugs/Defects
Early detection of flaws
Avoid Cost due to Rework and Delay
Higher Confidence
Everyone Happy
Software Negligence & Testing Coverage, Cem Kraner, 1995
The question is, what's wrong with this argument?
The Tragedy
of 100%
Code Coverage
How to reach 100% Code Coverage
____________________________________________
Every line of source code covered
Every underlying dependency is covered
Every possible representative input is covered
Every branch, condition and statement is covered
Every unexpected and error case is covered
Journey to Success ….
Do we really need 100% Code Coverage?
____________________________________________
Every high risk area is covered
Every Sprint we increase our test suite and coverage
Every test is valuable
Program
Mutant 1
Mutant 2
Mutant 3
Test
Suite
4. Compare
Test
Suite
Same
Same
Different
(“killed”)
1. Test
3. Test
Test Outputs
Test Outputs
2. Mutation
Operation
Adequacy:
= #Different / total
= 1/3
= 33%
Mutation Testing
Reruns unit tests against modified version of your code
The Good
Developer
linkedin.com/in/throthe/
thomas.rothe@devops.co.id
Thank You

More Related Content

What's hot

Myths in Software Requirements
Myths in Software RequirementsMyths in Software Requirements
Myths in Software Requirements
Sheraz Pervaiz
 
Test driven development
Test driven developmentTest driven development
Test driven development
Harry Potter
 
4.Security Assessment And Testing
4.Security Assessment And Testing4.Security Assessment And Testing
4.Security Assessment And Testing
phanleson
 

What's hot (16)

9. risk-management
9. risk-management9. risk-management
9. risk-management
 
Myths in Software Requirements
Myths in Software RequirementsMyths in Software Requirements
Myths in Software Requirements
 
Software Development in the Brave New world
Software Development in the Brave New worldSoftware Development in the Brave New world
Software Development in the Brave New world
 
Workshop on programming contest
Workshop on programming contestWorkshop on programming contest
Workshop on programming contest
 
SD & D analysis
SD & D analysisSD & D analysis
SD & D analysis
 
Coding and testing in Software Engineering
Coding and testing in Software EngineeringCoding and testing in Software Engineering
Coding and testing in Software Engineering
 
software myths
software mythssoftware myths
software myths
 
Agile code quality metrics
Agile code quality metricsAgile code quality metrics
Agile code quality metrics
 
Got Myth? Myths in Software Engineering
Got Myth? Myths in Software EngineeringGot Myth? Myths in Software Engineering
Got Myth? Myths in Software Engineering
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
11. estimation-1
11. estimation-111. estimation-1
11. estimation-1
 
1. The Software Development Process - Analysis
1. The Software Development Process - Analysis1. The Software Development Process - Analysis
1. The Software Development Process - Analysis
 
When, why and for whom do practitioners detect technical debts?: An experienc...
When, why and for whom do practitioners detect technical debts?: An experienc...When, why and for whom do practitioners detect technical debts?: An experienc...
When, why and for whom do practitioners detect technical debts?: An experienc...
 
Fundamentals of testing what is testing (reference graham et.al (2006))
Fundamentals of testing   what is testing (reference graham et.al (2006))Fundamentals of testing   what is testing (reference graham et.al (2006))
Fundamentals of testing what is testing (reference graham et.al (2006))
 
Competitive programming
Competitive  programmingCompetitive  programming
Competitive programming
 
4.Security Assessment And Testing
4.Security Assessment And Testing4.Security Assessment And Testing
4.Security Assessment And Testing
 

Similar to DevOpsDays Jakarta: Code Coverage - A dump metric for code quality

5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
5WCSQ - Quality Improvement by the Real-Time Detection of the Problems5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
Takanori Suzuki
 
Embedded software static analysis_Polyspace-WhitePaper_final
Embedded software static analysis_Polyspace-WhitePaper_finalEmbedded software static analysis_Polyspace-WhitePaper_final
Embedded software static analysis_Polyspace-WhitePaper_final
TAMILMARAN C
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective
Engineering Software Lab
 
caring_about_code_quality
caring_about_code_qualitycaring_about_code_quality
caring_about_code_quality
Ketan Patel
 

Similar to DevOpsDays Jakarta: Code Coverage - A dump metric for code quality (20)

Code Coverage - A Dump Metric
Code Coverage - A Dump MetricCode Coverage - A Dump Metric
Code Coverage - A Dump Metric
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
 
5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
5WCSQ - Quality Improvement by the Real-Time Detection of the Problems5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
5WCSQ - Quality Improvement by the Real-Time Detection of the Problems
 
Removing-the-cost-coding-errors-in-building-materials
 Removing-the-cost-coding-errors-in-building-materials Removing-the-cost-coding-errors-in-building-materials
Removing-the-cost-coding-errors-in-building-materials
 
Embedded software static analysis_Polyspace-WhitePaper_final
Embedded software static analysis_Polyspace-WhitePaper_finalEmbedded software static analysis_Polyspace-WhitePaper_final
Embedded software static analysis_Polyspace-WhitePaper_final
 
Software coding and testing
Software coding and testingSoftware coding and testing
Software coding and testing
 
01 the value of quality
01   the value of quality01   the value of quality
01 the value of quality
 
Code coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspectiveCode coverage in theory and in practice form the do178 b perspective
Code coverage in theory and in practice form the do178 b perspective
 
Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective   Code Coverage in Theory and in practice form the DO178B perspective
Code Coverage in Theory and in practice form the DO178B perspective
 
caring_about_code_quality
caring_about_code_qualitycaring_about_code_quality
caring_about_code_quality
 
Defect Tracking Software Project Presentation
Defect Tracking Software Project PresentationDefect Tracking Software Project Presentation
Defect Tracking Software Project Presentation
 
Quality Assurance and its Importance in Software Industry by Aman Shukla
Quality Assurance and its Importance in Software Industry by Aman ShuklaQuality Assurance and its Importance in Software Industry by Aman Shukla
Quality Assurance and its Importance in Software Industry by Aman Shukla
 
Test-Driven Code Review: An Empirical Study
Test-Driven Code Review: An Empirical StudyTest-Driven Code Review: An Empirical Study
Test-Driven Code Review: An Empirical Study
 
Zero-bug Software, Mathematically Guaranteed
Zero-bug Software, Mathematically GuaranteedZero-bug Software, Mathematically Guaranteed
Zero-bug Software, Mathematically Guaranteed
 
[India Merge World Tour] Coverity
[India Merge World Tour] Coverity[India Merge World Tour] Coverity
[India Merge World Tour] Coverity
 
Automating The Process For Building Reliable Software
Automating The Process For Building Reliable SoftwareAutomating The Process For Building Reliable Software
Automating The Process For Building Reliable Software
 
Future of QA
Future of QAFuture of QA
Future of QA
 
Futureofqa
FutureofqaFutureofqa
Futureofqa
 
Refactoring to Testable Code
Refactoring to Testable CodeRefactoring to Testable Code
Refactoring to Testable Code
 
Compliance as Code Everywhere
Compliance as Code EverywhereCompliance as Code Everywhere
Compliance as Code Everywhere
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

DevOpsDays Jakarta: Code Coverage - A dump metric for code quality

Editor's Notes

  1. For a metric to be “good” in this context Like all metrics, it can be fooled
  2. Why we actually care about code coverage… Finds Software Bugs Early
  3. Whenever you use Unit Testing or Integration Testing, you typically look at Code Coverage which is a … The degree here is a percentage of source code that is covered by automated tests. Mostly Unit and Integration tests The lines in the code that are executed when one of the automated tests run, expressed as a percentage of the entire codebase. For example, 65% code coverage would mean that the tests execute 65% of the code. Function coverage: how many of the functions defined have been called. Statement coverage: how many of the statements in the program have been executed. Branches coverage: how many of the branches of the control structures (if statements for instance) have been executed. Condition coverage: how many of the boolean sub-expressions have been tested for a true and a false value. Line coverage: how many of lines of source code have been tested.
  4. Lets look at an example So, I believe we all agree that we would try to aim for a high code coverage, but what exactly would it tell us? So what does a high code coverage percentage tell us?
  5. So what does 100% code coverage look like here? A developer could get 100% code coverage for that method with a single short test.  Unfortunately, that one line method has an insane amount of complexity and should actually contain perhaps hundreds of tests, not one of which will increase the code coverage metric beyond the first.So what do we know? When we have 100% test coverage we know that a test has ran all of the lines in this code. Cool, so it’s fully tested! It’s measurements are reliable when you’re tracking how much of your code is ran by your tests but it tells you absolutely nothing of the value of those tests.
  6. If you're concerned that sneaky developers will find some way to cheat the number, make themselves look good, and not increase quality at all, you're not entirely wrong.  As with any metric, coverage can be cheated, abused, and broken.   Managers often misunderstood the meaning of Code Coverage I expect a high level of coverage Suppose a manager requires some level of coverage, perhaps 85%, as a "shipping gate". The product is not done - and you can't ship - until you have 85% coverage.7 The problem with this approach is that people optimize their performance according to how they’re measured. You can get 85% coverage by looking at the coverage conditions, picking the ones that seem easiest to satisfy, writing quick tests for them, and iterating until done. That's faster than thinking of coverage conditions as clues pointing to weaknesses in the test design. It's especially faster because thinking about test design might lead to "redundant" tests that don't increase coverage at all. They only find bugs
  7. Lets fool around
  8. Case: I had to review source code on an existing project which was made by a service vendor. I found a "funny" and really dirty way used on a class just to achieve the minimal amount of code coverage. A specific project folder for certain functionality consisted of 12 classes and I found that all of them had a static method called fakeMethod. Then I found one test class that contains only one method calling those fakeMethod for each class which exactly pushed the Code Coverage to the Shipping Gate we used.
  9. Code Coverage provides us useful and actionable insights into your code. With modern tools, we can see areas of the program that are weakly tested, However, Bad code coverage is usually a symptom of badly tested code, but good code coverage certainly does not guarantee good source code or good tested source code It’s measurements are reliable when you’re tracking how much of your code is ran by your tests but it tells you absolutely nothing of the value of those tests. Visualizing it on its own is useless because it has no reliable, predictive relationship with the quality of the code or the tests. 
  10. The goal of test coverage targets is a noble one. By striving to ensure that every line of code is tested, you theoretically reduce the likelihood of a defect going into production unnoticed until an unfortunate customer stumbles across it. However, in reality you run the risk of becoming a slave to this number and writing a whole host of pointless tests that exist for the sole purpose of meeting the minimum coverage requirement. At this point, take a step back and think about why we even write tests. Coverage numbers (like many numbers) are dangerous because they're objective but incomplete. They too often distort sensible action. Using them in isolation is as foolish as hiring based only on GPA
  11. Teams writes more valuable tests, their code will become more testable Their testable code will become more loosely coupled and better architected Their bugs will regress less often, they'll end up with verifiable documentation, and small refactoring's will become more common because they are safer and easier.  In short the team will increase in maturity and their product will increase in quality.
  12. Goal: kill all mutants! Faults are created Way for testing quality of tests Modifies a program in small ways, each mutated version is called a mutant and tests detect and reject mutants by causing the behaviour of the original version Tests suites are measured by the percentage of mutants that they killed Mutants are based on well-defined mutation operators Mimic typical programming errors, Wrong variable name Wrong operator Diving by zero Statement deletion Replacing Branch (Boolean condition) boundary conditions {TBD} (>,<=) Replacing arithmetic operators {+, -, *, /, %} Replacing bitwise operators {&, |, ^} Replacing reads from parameters Replacing writes to local variables of the same type with each other. Used to help tester develop effective tests or locate weakness in the test date Kind of white box tests It demonstrates the effectiveness of test cases Run after unit test suites, takes longer Example: .NET Ninja Turtles, CREAM Replacing writes to local variables of the same type with each other.
  13. Writing proper Unit Testing is
  14. Take away: don’t blindly trust Code Coverage