SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Release the
Mutants
And validate your tests
Keir Bowden, CTO BrightGen
@bob_buzzard
About me
CTO at BrightGen
Salesforce MVP
14 years Salesforce
35 years experience
Agenda
The need for mutation testing
What is mutation testing?
Mutation testing in practice
bbmutants CLI Plug-in
Key Learnings
The need for
mutation testing
The Need
Production
Code
Unit
Tests
Quality
The Need
The Need
The Need
The Need
The Need
The Need
Quis custodiet ipsos custodes?
Who will guard the guards themselves?
How do you tests your tests?
Changing code should cause test failures
Enter the mutants!
What is Mutation Testing?
1. Competent Programmer
● Code is close to correct
● Most faults are simple mistakes
2. Coupling Effects
● Simple faults are coupled to complex faults
● Fixing simple faults will fix complex faults
● Tests that detect mutants would also detect real bugs
Two Hypotheses
Fault based testing - intentionally break code
1. Test original class
2. Create mutant class - change one aspect
3. Test mutant class
4. Compare test results
“Open Box” testing - knows about internals
Mutation testing
R. Lipton, “Fault Diagnosis of Computer Programs”, Student Report, Carnegie Mellon University, 1971
Mutation Testing
Original
Mutant
Mutant Killed
● Changing code breaks tests
● Mutant is covered by test case
Mutant Survived
● Changing code did not break test
● Mutant is not covered by test case, or
● Mutant is equivalent to original class
Mutation Testing
Syntax changed
Functionality did not
Suppress (aka delete) them
Equivalent Mutant
Mutations
Type Example
Boolean Operator Replace && with ||
Comparison Operator Replace == with !=, >=, <=
Increment Replace ++ with --
Method Call Replace System.now() with System.now.addHours(17)
Constant Replace 250000 with 275000
Return Values Replace return true with return false
Delete Code Remove lines containing DML statements
Mutation Testing in Practice
One change per mutant
Avoid multiple mutations of the same line
Limit mutations of a single class
Large test suite means fewer mutants
● Target specific classes
Generating Mutants
Generate new mutants for each cycle
● They can’t get any deader
● Avoids maintenance overhead
Chance of regenerating identical mutants
● Change tactics
● Target only updated files
Generating Mutants
Computationally expensive
For each mutant
● Replace original code
● Deploy mutant
● Run entire test suite
● Restore original code
Execute, evaluate, repeat
● Execute every mutant, every time
Executing Mutants
Some mutants will not deploy
● Not a weakness of tests
● Developers should spot this!
● Continuous integration will catch this
Suppress (aka delete) them
Executing Mutants
Expensive
● Human Oracle required
● Manual checks for all survivors
Suppress equivalents
Calculate mutation score
● Indicator of test quality
Fix tests
● Ensure original code is still green
Evaluating, or Counting the Bodies
killed mutants
total mutants
Mutation Score
* 100
Well suited to automation
● What changes is less important than something changed
● Simple “mistakes” introduced
● Coupling effect says real bugs would be found
Repeated deploy/execute tests
Automation
New scratch org for cycle
Source tracking detects changes
● Replace production class with mutant on filesystem
● Reverse after testing
CLI to push source and run tests
SFDX is Key
bbmutants CLI Plug-in
bbmutants:generate
Once per cycle
Configurable
● Target specific files
● Limit mutants per file
● Specify strings to replace
● Specify values to replace
Generate Mutants
Avoid repetition - randomise:
● Starting line in file (if limiting mutants)
● Choice of mutation
● Choice of constant
● Choice of comparison operator
Generate Mutants
bbmutants:execute
Deploy and run tests
● Delete mutants that won’t deploy
List survivors
Calculate mutation score
Iterative, after fixing tests
● Delete equivalents
Execute Mutants
Plug-in Demo
Key Learnings
Allow sufficient time
Easier with smaller files
● Fewer mutants
Mutation scores won’t surprise you!
● Lots of test effort = high score
● Focus on coverage = low score
Key Learnings
Mutation test at the end of development
Automatically generated perform as well as hand crafted
Constants are less helpful than expected
● Tests typically reference production values
Removing DML didn’t break tests
● Tendency to check returned value over database contents
Key Learnings
Key Learnings
Pros Cons
Detect untested code Vast number of potential mutants
Measurable mutation score Manual verification of surviving mutants
Improve test suite quality Full test run for each mutant
Tests how the code doesn’t work Knowledge of code internals required
CLI Plug-in on NPM - https://bobbuzz.me.uk/mutationplugin
sfdx plugins:install bbmutation
Source on Github - https://bobbuzz.me.uk/mutationsrc
Resources
Connect with Developer
Trailblazers from Anywhere
Join the
Community
www.salesforce.com/devcommunity/
#SFDevsAMA
40
Thank
you

Más contenido relacionado

Similar a Mutation Testing.pdf

Testing & continuous delivery
Testing & continuous deliveryTesting & continuous delivery
Testing & continuous deliveryNelson Melina
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingCameron Presley
 
Mutation testing pixels camp 2019
Mutation testing   pixels camp 2019Mutation testing   pixels camp 2019
Mutation testing pixels camp 2019Pedro Rijo
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsRoy van Rijn
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnNLJUG
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
 
Joker - Improve your tests with mutation testing
Joker - Improve your tests with mutation testingJoker - Improve your tests with mutation testing
Joker - Improve your tests with mutation testingNicolas Fränkel
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Abhijeet Vaikar
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
Utility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDDUtility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDDXP Conference India
 
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsI.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsNicolas Fränkel
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentdcsunu
 
SSBSE 2020 keynote
SSBSE 2020 keynoteSSBSE 2020 keynote
SSBSE 2020 keynoteShiva Nejati
 

Similar a Mutation Testing.pdf (20)

Testing & continuous delivery
Testing & continuous deliveryTesting & continuous delivery
Testing & continuous delivery
 
des mutants dans le code.pdf
des mutants dans le code.pdfdes mutants dans le code.pdf
des mutants dans le code.pdf
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 
Mutation testing pixels camp 2019
Mutation testing   pixels camp 2019Mutation testing   pixels camp 2019
Mutation testing pixels camp 2019
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
MuFinal
MuFinalMuFinal
MuFinal
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your tests
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van Rijn
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Joker - Improve your tests with mutation testing
Joker - Improve your tests with mutation testingJoker - Improve your tests with mutation testing
Joker - Improve your tests with mutation testing
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Utility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDDUtility of Test Coverage Metrics in TDD
Utility of Test Coverage Metrics in TDD
 
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsI.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd
TddTdd
Tdd
 
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
Javantura v3 - Mutation Testing for everyone – Nicolas FränkelJavantura v3 - Mutation Testing for everyone – Nicolas Fränkel
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
 
SSBSE 2020 keynote
SSBSE 2020 keynoteSSBSE 2020 keynote
SSBSE 2020 keynote
 

Más de Keir Bowden

LC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingLC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingKeir Bowden
 
London Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseLondon Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseKeir Bowden
 
London Salesforce Developer January 2022
London Salesforce Developer January 2022London Salesforce Developer January 2022
London Salesforce Developer January 2022Keir Bowden
 
Winter 22 for Developers
Winter 22 for DevelopersWinter 22 for Developers
Winter 22 for DevelopersKeir Bowden
 
Londons Calling 2021
Londons Calling 2021Londons Calling 2021
Londons Calling 2021Keir Bowden
 
London Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringLondon Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringKeir Bowden
 
Helsinki developer group march 2020
Helsinki developer group march 2020Helsinki developer group march 2020
Helsinki developer group march 2020Keir Bowden
 
London's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InLondon's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InKeir Bowden
 
Lightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSLightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSKeir Bowden
 
Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Keir Bowden
 
Salesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesSalesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesKeir Bowden
 
UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019Keir Bowden
 
Salesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresSalesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresKeir Bowden
 
Quickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIQuickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIKeir Bowden
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018Keir Bowden
 
Getting started with public speaking
Getting started with public speakingGetting started with public speaking
Getting started with public speakingKeir Bowden
 
London's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemLondon's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemKeir Bowden
 
No Connection? No Problem!
No Connection? No Problem!No Connection? No Problem!
No Connection? No Problem!Keir Bowden
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineKeir Bowden
 

Más de Keir Bowden (20)

LC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingLC 2022 - Second Generation Packaging
LC 2022 - Second Generation Packaging
 
London Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseLondon Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce Release
 
London Salesforce Developer January 2022
London Salesforce Developer January 2022London Salesforce Developer January 2022
London Salesforce Developer January 2022
 
Winter 22 for Developers
Winter 22 for DevelopersWinter 22 for Developers
Winter 22 for Developers
 
Londons Calling 2021
Londons Calling 2021Londons Calling 2021
Londons Calling 2021
 
London Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringLondon Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global Gathering
 
Helsinki developer group march 2020
Helsinki developer group march 2020Helsinki developer group march 2020
Helsinki developer group march 2020
 
London's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InLondon's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-In
 
Lightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSLightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JS
 
Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet
 
Salesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesSalesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 Features
 
UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019
 
Salesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresSalesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 features
 
Quickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIQuickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLI
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018
 
Getting started with public speaking
Getting started with public speakingGetting started with public speaking
Getting started with public speaking
 
Salesforce CLI
Salesforce CLISalesforce CLI
Salesforce CLI
 
London's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemLondon's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No Problem
 
No Connection? No Problem!
No Connection? No Problem!No Connection? No Problem!
No Connection? No Problem!
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with Jasmine
 

Último

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goahorny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goasexy call girls service in goa
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 

Último (20)

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goahorny (9316020077 ) Goa  Call Girls Service by VIP Call Girls in Goa
horny (9316020077 ) Goa Call Girls Service by VIP Call Girls in Goa
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
10.pdfMature Call girls in Dubai +971563133746 Dubai Call girls
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 

Mutation Testing.pdf

  • 1. Release the Mutants And validate your tests Keir Bowden, CTO BrightGen @bob_buzzard
  • 2. About me CTO at BrightGen Salesforce MVP 14 years Salesforce 35 years experience
  • 3. Agenda The need for mutation testing What is mutation testing? Mutation testing in practice bbmutants CLI Plug-in Key Learnings
  • 12. Quis custodiet ipsos custodes? Who will guard the guards themselves? How do you tests your tests? Changing code should cause test failures Enter the mutants!
  • 13. What is Mutation Testing?
  • 14. 1. Competent Programmer ● Code is close to correct ● Most faults are simple mistakes 2. Coupling Effects ● Simple faults are coupled to complex faults ● Fixing simple faults will fix complex faults ● Tests that detect mutants would also detect real bugs Two Hypotheses
  • 15. Fault based testing - intentionally break code 1. Test original class 2. Create mutant class - change one aspect 3. Test mutant class 4. Compare test results “Open Box” testing - knows about internals Mutation testing R. Lipton, “Fault Diagnosis of Computer Programs”, Student Report, Carnegie Mellon University, 1971
  • 17. Mutant Killed ● Changing code breaks tests ● Mutant is covered by test case Mutant Survived ● Changing code did not break test ● Mutant is not covered by test case, or ● Mutant is equivalent to original class Mutation Testing
  • 18. Syntax changed Functionality did not Suppress (aka delete) them Equivalent Mutant
  • 19. Mutations Type Example Boolean Operator Replace && with || Comparison Operator Replace == with !=, >=, <= Increment Replace ++ with -- Method Call Replace System.now() with System.now.addHours(17) Constant Replace 250000 with 275000 Return Values Replace return true with return false Delete Code Remove lines containing DML statements
  • 21. One change per mutant Avoid multiple mutations of the same line Limit mutations of a single class Large test suite means fewer mutants ● Target specific classes Generating Mutants
  • 22. Generate new mutants for each cycle ● They can’t get any deader ● Avoids maintenance overhead Chance of regenerating identical mutants ● Change tactics ● Target only updated files Generating Mutants
  • 23. Computationally expensive For each mutant ● Replace original code ● Deploy mutant ● Run entire test suite ● Restore original code Execute, evaluate, repeat ● Execute every mutant, every time Executing Mutants
  • 24. Some mutants will not deploy ● Not a weakness of tests ● Developers should spot this! ● Continuous integration will catch this Suppress (aka delete) them Executing Mutants
  • 25. Expensive ● Human Oracle required ● Manual checks for all survivors Suppress equivalents Calculate mutation score ● Indicator of test quality Fix tests ● Ensure original code is still green Evaluating, or Counting the Bodies killed mutants total mutants Mutation Score * 100
  • 26. Well suited to automation ● What changes is less important than something changed ● Simple “mistakes” introduced ● Coupling effect says real bugs would be found Repeated deploy/execute tests Automation
  • 27. New scratch org for cycle Source tracking detects changes ● Replace production class with mutant on filesystem ● Reverse after testing CLI to push source and run tests SFDX is Key
  • 29. bbmutants:generate Once per cycle Configurable ● Target specific files ● Limit mutants per file ● Specify strings to replace ● Specify values to replace Generate Mutants
  • 30. Avoid repetition - randomise: ● Starting line in file (if limiting mutants) ● Choice of mutation ● Choice of constant ● Choice of comparison operator Generate Mutants
  • 31. bbmutants:execute Deploy and run tests ● Delete mutants that won’t deploy List survivors Calculate mutation score Iterative, after fixing tests ● Delete equivalents Execute Mutants
  • 34. Allow sufficient time Easier with smaller files ● Fewer mutants Mutation scores won’t surprise you! ● Lots of test effort = high score ● Focus on coverage = low score Key Learnings
  • 35. Mutation test at the end of development Automatically generated perform as well as hand crafted Constants are less helpful than expected ● Tests typically reference production values Removing DML didn’t break tests ● Tendency to check returned value over database contents Key Learnings
  • 36. Key Learnings Pros Cons Detect untested code Vast number of potential mutants Measurable mutation score Manual verification of surviving mutants Improve test suite quality Full test run for each mutant Tests how the code doesn’t work Knowledge of code internals required
  • 37. CLI Plug-in on NPM - https://bobbuzz.me.uk/mutationplugin sfdx plugins:install bbmutation Source on Github - https://bobbuzz.me.uk/mutationsrc Resources
  • 38.
  • 39. Connect with Developer Trailblazers from Anywhere Join the Community www.salesforce.com/devcommunity/ #SFDevsAMA