SlideShare a Scribd company logo
1 of 37
Download to read offline
What Test Coverage
Mean to us?
Joseph Yao
Tuesday, July 9, 13
Who I am?
n Agile Coach at Odd-e
n Father, Husband...
n Software Craftsman
n Basketball, Board Game...
Tuesday, July 9, 13
Agenda
n Bias and Truth of Test Coverage
n Classical Test Coverage
n Mutation Test Coverage
n TDD and Test Coverage
Tuesday, July 9, 13
Bias of Test Coverage
Tuesday, July 9, 13
Truth of Test Coverage
I expect a high level of coverage. Sometimes
managers require one. There's a subtle difference.
-- Brian Marick
http://martinfowler.com/bliki/TestCoverage.html
Tuesday, July 9, 13
Truth of Test Coverage
Tuesday, July 9, 13
Classical Test Coverage
Tuesday, July 9, 13
Function Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
Satisfied Test: foo(2, 2)
Tuesday, July 9, 13
Function Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
Tuesday, July 9, 13
Statement Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
Satisfied Test: foo(2, 2)
Tuesday, July 9, 13
Statement Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
Unsatisfied Test: foo(2, -1)
Tuesday, July 9, 13
Decision Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
T/F
Satisfied Test: foo(2, 2), foo(-1, 2)
Tuesday, July 9, 13
Decision Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
T/F
Unsatisfied Test: foo(2, 2)
Tuesday, July 9, 13
Condition Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
T/F
Satisfied Test: foo(2, 2), foo(2, -1), foo(-1, -1)
T/F
Tuesday, July 9, 13
Condition Coverage
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
T/F
Unsatisfied Test: foo(2, 2), foo(-1, 2)
T/F
Tuesday, July 9, 13
Classical Test Coverage
Tuesday, July 9, 13
Classical Test Coverage
Tuesday, July 9, 13
Expectation of Automated Test
Tuesday, July 9, 13
Expectation of Automated Test
Any Possible “Bad” Code
Change can be Detected
Tuesday, July 9, 13
Mutation Test Coverage
Tuesday, July 9, 13
Why Mutation Test
Tuesday, July 9, 13
Redundant Code?
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
sideEffect(z);
return z;
}
Tuesday, July 9, 13
Redundant Code?
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
sideEffect(z);
return z;
}
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
sideEffect(z);
return z;
}
Tuesday, July 9, 13
Redundant Code?
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
sideEffect(z);
return z;
}
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
sideEffect(z);
return z;
}
n Missing test to prove the sideEffect call is needed
n If code is redundant, it can’t be learnt via any
classical test coverage
Tuesday, July 9, 13
Conditional Boundary Mutator
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
Condition Coverage Satisfied Test:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, -1))
assertEquals(0, foo(-1, 2))
Tuesday, July 9, 13
Conditional Boundary Mutator
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>=0)) {
z = x;
}
return z;
}
Condition Coverage Satisfied Test:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, -1))
assertEquals(0, foo(-1, 2))
Tuesday, July 9, 13
Conditional Boundary Mutator
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>=0)) {
z = x;
}
return z;
}
Condition Coverage Satisfied Test:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, -1))
assertEquals(0, foo(-1, 2))
Test to cover this Mutator:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, 0))
assertEquals(0, foo(-1, 2))
Tuesday, July 9, 13
Conditional Boundary Mutator
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>0)) {
z = x;
}
return z;
}
int foo (int x, int y)
{
int z = 0;
if ((x>0) && (y>=0)) {
z = x;
}
return z;
}
Condition Coverage Satisfied Test:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, -1))
assertEquals(0, foo(-1, 2))
n Test not prevent “bad” code change to happen
Test to cover this Mutator:
assertEquals(2, foo(2, 2))
assertEquals(0, foo(2, 0))
assertEquals(0, foo(-1, 2))
Tuesday, July 9, 13
Other Mutators
n Negate Conditionals Mutator
n Math Mutator
n Increments Mutator
n Invert Negatives Mutator
n Inline Constant Mutator
n Return Values Mutator
n Void Method Calls Mutator
n Non Void Method Calls Mutator
n Constructor Calls Mutator
Tuesday, July 9, 13
Test Driven Development
Tuesday, July 9, 13
TDD and Test Coverage
n You can most likely ignore Classical Test Coverage
n You can’t ignore Mutation Test Coverage
n If not TDD, then you can learn a lot from both
Classical and Mutation Test Coverage
Tuesday, July 9, 13
PokerHands Kata
Tuesday, July 9, 13
True Mutation
Tuesday, July 9, 13
Problematic Test
Tuesday, July 9, 13
False Mutation
Tuesday, July 9, 13
Reference
n Martin Fowler’s blog http://martinfowler.com/bliki/
TestCoverage.html
n Mutation Test Wikipedia http://en.wikipedia.org/
wiki/Mutation_testing
n Mutation Test Analysis Report http://
crestweb.cs.ucl.ac.uk/resources/
mutation_testing_repository/TR-09-06.pdf
Tuesday, July 9, 13
Q & A
新浪微博:姚若舟
微信:yaoruozhou
土豆(Kata视频):姚若舟
Github: JosephYao
Tuesday, July 9, 13

More Related Content

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

What test coverage mean to us

  • 1. What Test Coverage Mean to us? Joseph Yao Tuesday, July 9, 13
  • 2. Who I am? n Agile Coach at Odd-e n Father, Husband... n Software Craftsman n Basketball, Board Game... Tuesday, July 9, 13
  • 3. Agenda n Bias and Truth of Test Coverage n Classical Test Coverage n Mutation Test Coverage n TDD and Test Coverage Tuesday, July 9, 13
  • 4. Bias of Test Coverage Tuesday, July 9, 13
  • 5. Truth of Test Coverage I expect a high level of coverage. Sometimes managers require one. There's a subtle difference. -- Brian Marick http://martinfowler.com/bliki/TestCoverage.html Tuesday, July 9, 13
  • 6. Truth of Test Coverage Tuesday, July 9, 13
  • 8. Function Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } Satisfied Test: foo(2, 2) Tuesday, July 9, 13
  • 9. Function Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } Tuesday, July 9, 13
  • 10. Statement Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } Satisfied Test: foo(2, 2) Tuesday, July 9, 13
  • 11. Statement Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } Unsatisfied Test: foo(2, -1) Tuesday, July 9, 13
  • 12. Decision Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } T/F Satisfied Test: foo(2, 2), foo(-1, 2) Tuesday, July 9, 13
  • 13. Decision Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } T/F Unsatisfied Test: foo(2, 2) Tuesday, July 9, 13
  • 14. Condition Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } T/F Satisfied Test: foo(2, 2), foo(2, -1), foo(-1, -1) T/F Tuesday, July 9, 13
  • 15. Condition Coverage int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } T/F Unsatisfied Test: foo(2, 2), foo(-1, 2) T/F Tuesday, July 9, 13
  • 18. Expectation of Automated Test Tuesday, July 9, 13
  • 19. Expectation of Automated Test Any Possible “Bad” Code Change can be Detected Tuesday, July 9, 13
  • 22. Redundant Code? int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } sideEffect(z); return z; } Tuesday, July 9, 13
  • 23. Redundant Code? int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } sideEffect(z); return z; } int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } sideEffect(z); return z; } Tuesday, July 9, 13
  • 24. Redundant Code? int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } sideEffect(z); return z; } int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } sideEffect(z); return z; } n Missing test to prove the sideEffect call is needed n If code is redundant, it can’t be learnt via any classical test coverage Tuesday, July 9, 13
  • 25. Conditional Boundary Mutator int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } Condition Coverage Satisfied Test: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, -1)) assertEquals(0, foo(-1, 2)) Tuesday, July 9, 13
  • 26. Conditional Boundary Mutator int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } int foo (int x, int y) { int z = 0; if ((x>0) && (y>=0)) { z = x; } return z; } Condition Coverage Satisfied Test: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, -1)) assertEquals(0, foo(-1, 2)) Tuesday, July 9, 13
  • 27. Conditional Boundary Mutator int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } int foo (int x, int y) { int z = 0; if ((x>0) && (y>=0)) { z = x; } return z; } Condition Coverage Satisfied Test: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, -1)) assertEquals(0, foo(-1, 2)) Test to cover this Mutator: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, 0)) assertEquals(0, foo(-1, 2)) Tuesday, July 9, 13
  • 28. Conditional Boundary Mutator int foo (int x, int y) { int z = 0; if ((x>0) && (y>0)) { z = x; } return z; } int foo (int x, int y) { int z = 0; if ((x>0) && (y>=0)) { z = x; } return z; } Condition Coverage Satisfied Test: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, -1)) assertEquals(0, foo(-1, 2)) n Test not prevent “bad” code change to happen Test to cover this Mutator: assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, 0)) assertEquals(0, foo(-1, 2)) Tuesday, July 9, 13
  • 29. Other Mutators n Negate Conditionals Mutator n Math Mutator n Increments Mutator n Invert Negatives Mutator n Inline Constant Mutator n Return Values Mutator n Void Method Calls Mutator n Non Void Method Calls Mutator n Constructor Calls Mutator Tuesday, July 9, 13
  • 31. TDD and Test Coverage n You can most likely ignore Classical Test Coverage n You can’t ignore Mutation Test Coverage n If not TDD, then you can learn a lot from both Classical and Mutation Test Coverage Tuesday, July 9, 13
  • 36. Reference n Martin Fowler’s blog http://martinfowler.com/bliki/ TestCoverage.html n Mutation Test Wikipedia http://en.wikipedia.org/ wiki/Mutation_testing n Mutation Test Analysis Report http:// crestweb.cs.ucl.ac.uk/resources/ mutation_testing_repository/TR-09-06.pdf Tuesday, July 9, 13