SlideShare uma empresa Scribd logo
1 de 90
An introduction to
mutation testing                       1


David Musgrove
Lead developer of NinjaTurtles
Author of Tests and testability blog
Overview




           2
Overview
What is mutation testing?




                            2
Overview
What is mutation testing?
How do we do mutation testing?




                                 2
Overview
What is mutation testing?
How do we do mutation testing?
Why do we do mutation testing?




                                 2
Overview
What is mutation testing?
How do we do mutation testing?
Why do we do mutation testing?
What are the disadvantages?




                                 2
Overview
What is mutation testing?
How do we do mutation testing?
Why do we do mutation testing?
What are the disadvantages?
Conclusions




                                 2
What is mutation testing?   3
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail

    ■ Failing is the new passing—the mutant should break the tests
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail

    ■ Failing is the new passing—the mutant should break the tests
    ■ The tests collectively should fail, not every individual test
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail

    ■ Failing is the new passing—the mutant should break the tests
    ■ The tests collectively should fail, not every individual test
 ■ It indicates how well your code is covered by your suite of tests
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail

    ■ Failing is the new passing—the mutant should break the tests
    ■ The tests collectively should fail, not every individual test
 ■ It indicates how well your code is covered by your suite of tests
    ■ Mutation testing doesn’t test your code, it tests your tests
What is mutation testing?                                               3


 ■ It is the technique of running your tests over deliberately broken
    versions (mutants) of your code to make sure they fail

    ■ Failing is the new passing—the mutant should break the tests
    ■ The tests collectively should fail, not every individual test
 ■ It indicates how well your code is covered by your suite of tests
    ■ Mutation testing doesn’t test your code, it tests your tests
 ■ It is not new—the concept was introduced by Richard Lipton in 1971
How do we “break” the code?   4
How do we “break” the code?                                4



 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
How do we “break” the code?                                             4



 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
    ■ Errors can be introduced, for example division by zero—but this
       should just produce a test failure, which is fine
How do we “break” the code?                                             4



 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
    ■ Errors can be introduced, for example division by zero—but this
       should just produce a test failure, which is fine

 ■ Example: swap comparison operators ==, !=, <=, <, >=, >
How do we “break” the code?                                               4



 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
    ■ Errors can be introduced, for example division by zero—but this
       should just produce a test failure, which is fine

 ■ Example: swap comparison operators ==, !=, <=, <, >=, >
    ■ Can introduce invariants, for example == and >= can be equivalent
       checking the upper limit of a loop counter, so handle with care
How do we “break” the code?                                               4



 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
    ■ Errors can be introduced, for example division by zero—but this
       should just produce a test failure, which is fine

 ■ Example: swap comparison operators ==, !=, <=, <, >=, >
    ■ Can introduce invariants, for example == and >= can be equivalent
       checking the upper limit of a loop counter, so handle with care

 ■ Example: delete “statements” (e.g. .NET IL sequence points)
Then what?   5
Then what?                                                      5



 ■ We save the mutated code and run the test suite against it
Then what?                                                      5



 ■ We save the mutated code and run the test suite against it
 ■ We hope the test suite fails and the mutant is “killed”
Then what?                                                           5



 ■ We save the mutated code and run the test suite against it
 ■ We hope the test suite fails and the mutant is “killed”
 ■ If the mutant survives, then further investigation is necessary
Then what?                                                           5



 ■ We save the mutated code and run the test suite against it
 ■ We hope the test suite fails and the mutant is “killed”
 ■ If the mutant survives, then further investigation is necessary
    ■ We may have to add tests to kill the mutant
Then what?                                                           5



 ■ We save the mutated code and run the test suite against it
 ■ We hope the test suite fails and the mutant is “killed”
 ■ If the mutant survives, then further investigation is necessary
    ■ We may have to add tests to kill the mutant
    ■ We may have to refactor the code to kill the mutant
Then what?                                                           5



 ■ We save the mutated code and run the test suite against it
 ■ We hope the test suite fails and the mutant is “killed”
 ■ If the mutant survives, then further investigation is necessary
    ■ We may have to add tests to kill the mutant
    ■ We may have to refactor the code to kill the mutant
    ■ Both are related to TDD—red, green refactor
Can I see an example?   6
Can I see an example?                                                             6


 ■ Here’s a simple method with a test   public int Subtract(int a, int b)
                                        {
                                            return a – b;
                                        }

                                        [Test]
                                        public void TestSubtract()
                                        {
                                            Assert.AreEqual(1, Subtract(3, 2));
                                        }


                                        Test passes
Can I see an example?                                                                    6


 ■ Here’s a simple method with a test          public int Subtract(int a, int b)
                                               {
                                                   return a – b;
 ■ We’re going to mutate the arithmetic        }
    operator, replacing it with addition and
                                               [Test]
    division                                   public void TestSubtract()
                                               {
                                                   Assert.AreEqual(1, Subtract(3, 2));
                                               }


                                               Test passes
Can I see an example?                                                                    6


 ■ Here’s a simple method with a test          public int Subtract(int a, int b)
                                               {
                                                   return a + b;
 ■ We’re going to mutate the arithmetic        }
    operator, replacing it with addition and
                                               [Test]
    division                                   public void TestSubtract()
                                               {
 ■ Let’s try addition: 3 + 2 = 5, so the       }
                                                   Assert.AreEqual(1, Subtract(3, 2));

    test fails—which is good
                                               Test fails
Can I see an example?                                                                    6


 ■ Here’s a simple method with a test          public int Subtract(int a, int b)
                                               {
                                                   return a / b;
 ■ We’re going to mutate the arithmetic        }
    operator, replacing it with addition and
                                               [Test]
    division                                   public void TestSubtract()
                                               {
 ■ Let’s try addition: 3 + 2 = 5, so the       }
                                                   Assert.AreEqual(1, Subtract(3, 2));

    test fails—which is good
                                               Test passes
 ■ Let’s try division: 3 / 2 = 1 (remember,
    this is integer division), so the test
    passes—which is bad
What does that show us?   7
What does that show us?           7


 ■ The division mutant survived
What does that show us?                      7


 ■ The division mutant survived
 ■ The existing test (suite) is inadequate
What does that show us?                                                                 7


 ■ The division mutant survived               public int Subtract(int a, int b)
                                              {
                                                  return a – b;
 ■ The existing test (suite) is inadequate    }

                                              [Test]
 ■ We need to improve the test(s)—the         public void TestSubtract()
    current test is far too simplistic with   {
                                                  Assert.AreEqual(1, Subtract(3, 2));
    just one simple assertion                 }



                                              Unit test passes
                                              Mutation testing fails
What does that show us?                                                                 7


 ■ The division mutant survived               public int Subtract(int a, int b)
                                              {
                                                  return a – b;
 ■ The existing test (suite) is inadequate    }

                                              [Test]
 ■ We need to improve the test(s)—the         public void TestSubtract()
    current test is far too simplistic with   {
                                                  Assert.AreEqual(1, Subtract(3, 2));
    just one simple assertion                 }

 ■ We add a second test assertion
                                              Unit test passes
                                              Mutation testing fails
What does that show us?                                                                  7


 ■ The division mutant survived               public int Subtract(int a, int b)
                                              {
                                                  return a – b;
 ■ The existing test (suite) is inadequate    }


 ■ We need to improve the test(s)—the         [Test]
                                              public void TestSubtract()
    current test is far too simplistic with   {
                                                  Assert.AreEqual(1, Subtract(3, 2));
    just one simple assertion                     Assert.AreEqual(5, Subtract(3, -2));
                                              }
 ■ We add a second test assertion
                                              Unit test passes
 ■ Here is the fixed test that now kills the   Mutation testing passes
    division mutant
How do we do mutation testing?   8
How do we do mutation testing?                                        8




 ■ Can be applied at source code, intermediate code (Java ByteCode,
    Microsoft IL) or compiled code level
How do we do mutation testing?                                          8




 ■ Can be applied at source code, intermediate code (Java ByteCode,
    Microsoft IL) or compiled code level

    ■ For Java and .NET, intermediate code is easiest to target in an
       automated solution as it has a relatively small set of well
       understood instructions and doesn’t require code parsing
How do we do mutation testing?                                          8




 ■ Can be applied at source code, intermediate code (Java ByteCode,
    Microsoft IL) or compiled code level

    ■ For Java and .NET, intermediate code is easiest to target in an
       automated solution as it has a relatively small set of well
       understood instructions and doesn’t require code parsing

 ■ Can be automated using a mutation testing tool
What tools are available?   9
What tools are available?                                                 9




 ■ There are a number of abortive open source attempts, or skeleton
    projects; only a few projects are actively maintained and developed
What tools are available?                                                 9




 ■ There are a number of abortive open source attempts, or skeleton
    projects; only a few projects are actively maintained and developed

 ■ The following show signs of meaningful activity within the last six
    months at the time of writing (August 2012)
What tools are available?                                                 9




 ■ There are a number of abortive open source attempts, or skeleton
    projects; only a few projects are actively maintained and developed

 ■ The following show signs of meaningful activity within the last six
    months at the time of writing (August 2012)

    ■ Java ByteCode mutation: PIT, Javalanche
What tools are available?                                                 9




 ■ There are a number of abortive open source attempts, or skeleton
    projects; only a few projects are actively maintained and developed

 ■ The following show signs of meaningful activity within the last six
    months at the time of writing (August 2012)

    ■ Java ByteCode mutation: PIT, Javalanche
    ■ .NET IL: NinjaTurtles
Why do we do mutation testing?   10
Why do we do mutation testing?                                            10



 ■ I like to think of it as a way of measuring a team’s test-drivenness
Why do we do mutation testing?                                            10



 ■ I like to think of it as a way of measuring a team’s test-drivenness
    ■ Test-driven development (TDD): write test, write code to make it
       pass, refactor (red, green, refactor)
Why do we do mutation testing?                                            10



 ■ I like to think of it as a way of measuring a team’s test-drivenness
    ■ Test-driven development (TDD): write test, write code to make it
       pass, refactor (red, green, refactor)

    ■ No code should be written that isn’t there to make a test pass
Why do we do mutation testing?                                            10



 ■ I like to think of it as a way of measuring a team’s test-drivenness
    ■ Test-driven development (TDD): write test, write code to make it
       pass, refactor (red, green, refactor)

    ■ No code should be written that isn’t there to make a test pass
    ■ Therefore if you mutate any code you should make a test fail
Why do we do mutation testing?                                            10



 ■ I like to think of it as a way of measuring a team’s test-drivenness
    ■ Test-driven development (TDD): write test, write code to make it
       pass, refactor (red, green, refactor)

    ■ No code should be written that isn’t there to make a test pass
    ■ Therefore if you mutate any code you should make a test fail
    ■ So perfect TDD implies 100% of (meaningful) mutants killed
YAMM—yet another maturity model   11
YAMM—yet another maturity model                                11


 ■ Level 0: code is tested when it is released, by the users
YAMM—yet another maturity model                                  11


 ■ Level 0: code is tested when it is released, by the users
 ■ Level 1: code is tested by dedicated testers before release
YAMM—yet another maturity model                                      11


 ■ Level 0: code is tested when it is released, by the users
 ■ Level 1: code is tested by dedicated testers before release
 ■ Level 2: code is also tested by the developers; some automation
YAMM—yet another maturity model                                          11


 ■ Level 0: code is tested when it is released, by the users
 ■ Level 1: code is tested by dedicated testers before release
 ■ Level 2: code is also tested by the developers; some automation
 ■ Level 3: tests are written first and automated as far as is possible
YAMM—yet another maturity model                                            11


 ■ Level 0: code is tested when it is released, by the users
 ■ Level 1: code is tested by dedicated testers before release
 ■ Level 2: code is also tested by the developers; some automation
 ■ Level 3: tests are written first and automated as far as is possible
 ■ Level 4: mutation testing is applied to verify efficacy of test suites
YAMM—yet another maturity model                                            11


 ■ Level 0: code is tested when it is released, by the users
 ■ Level 1: code is tested by dedicated testers before release
 ■ Level 2: code is also tested by the developers; some automation
 ■ Level 3: tests are written first and automated as far as is possible
 ■ Level 4: mutation testing is applied to verify efficacy of test suites
 ■ This could be a tree, with other ideas like BDD introduced, but it
    illustrates the position of mutation testing
What are the disadvantages?   12
What are the disadvantages?             12


 ■ Good tooling is only just emerging
What are the disadvantages?                             12


 ■ Good tooling is only just emerging
 ■ It’s relatively slow and computationally expensive
What are the disadvantages?                             12


 ■ Good tooling is only just emerging
 ■ It’s relatively slow and computationally expensive
    ■ Each line of code can produce many mutants
What are the disadvantages?                             12


 ■ Good tooling is only just emerging
 ■ It’s relatively slow and computationally expensive
    ■ Each line of code can produce many mutants
    ■ Each mutant requires a suite of tests to be run
What are the disadvantages?                                               12


 ■ Good tooling is only just emerging
 ■ It’s relatively slow and computationally expensive
    ■ Each line of code can produce many mutants
    ■ Each mutant requires a suite of tests to be run
    ■ But the suite of tests can be narrowed down, and it only needs to
       be run until the first failure is encountered
What are the disadvantages?                                               12


 ■ Good tooling is only just emerging
 ■ It’s relatively slow and computationally expensive
    ■ Each line of code can produce many mutants
    ■ Each mutant requires a suite of tests to be run
    ■ But the suite of tests can be narrowed down, and it only needs to
       be run until the first failure is encountered

    ■ And it’s eminently parallelisable for multicore PCs
What are the disadvantages?   13
What are the disadvantages?                                                       13




 ■ A passing mutation test can fail fast, but a failing mutation test is likely
    to take significantly longer as it runs the entire set of relevant tests
What are the disadvantages?                                                       13




 ■ A passing mutation test can fail fast, but a failing mutation test is likely
    to take significantly longer as it runs the entire set of relevant tests

    ■ So should be applied continuously to keep quality high
What are the disadvantages?                                                       13




 ■ A passing mutation test can fail fast, but a failing mutation test is likely
    to take significantly longer as it runs the entire set of relevant tests

    ■ So should be applied continuously to keep quality high
    ■ Can only realistically be applied in this way to code bases and test
        suites that are already in fairly good shape
A shameless plug for NinjaTurtles   14
A shameless plug for NinjaTurtles                             14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
A shameless plug for NinjaTurtles                             14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
 ■ Open source tool working at a .NET IL level
A shameless plug for NinjaTurtles                                  14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
 ■ Open source tool working at a .NET IL level
 ■ Includes seven different types of mutation at time of writing
A shameless plug for NinjaTurtles                                     14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
 ■ Open source tool working at a .NET IL level
 ■ Includes seven different types of mutation at time of writing
 ■ Compatible with existing .NET languages and unit test frameworks
A shameless plug for NinjaTurtles                                            14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
 ■ Open source tool working at a .NET IL level
 ■ Includes seven different types of mutation at time of writing
 ■ Compatible with existing .NET languages and unit test frameworks
 ■ Optimisations include parallelised test runs, reduced test suites, fail
    fast (where the underlying test runner supports it)
A shameless plug for NinjaTurtles                                            14


 ■ Disclaimer: I’m the lead developer on this so I’m biased
 ■ Open source tool working at a .NET IL level
 ■ Includes seven different types of mutation at time of writing
 ■ Compatible with existing .NET languages and unit test frameworks
 ■ Optimisations include parallelised test runs, reduced test suites, fail
    fast (where the underlying test runner supports it)

 ■ Console runner gives immediate results
Sample NinjaTurtles output   15
Sample NinjaTurtles output                                       15


                             ■ Simple console command
                               applied to one class within the
                               NinjaTurtles code base
Sample NinjaTurtles output                                        15


                             ■ Simple console command
                                applied to one class within the
                                NinjaTurtles code base

                             ■ Over 1,000 runs of the test
                                suite, each run as a separate
                                process
Sample NinjaTurtles output                                        15


                             ■ Simple console command
                                applied to one class within the
                                NinjaTurtles code base

                             ■ Over 1,000 runs of the test
                                suite, each run as a separate
                                process

                             ■ Test results returned in under
                                90 seconds
Sample NinjaTurtles output                                        15


                             ■ Simple console command
                                applied to one class within the
                                NinjaTurtles code base

                             ■ Over 1,000 runs of the test
                                suite, each run as a separate
                                process

                             ■ Test results returned in under
                                90 seconds

                             ■ Also XML or HTML output
Conclusions   16
Conclusions                                                                  16


 ■ Mutation testing has a lot to offer teams looking to constantly improve
    the way they do things
Conclusions                                                                  16


 ■ Mutation testing has a lot to offer teams looking to constantly improve
    the way they do things

 ■ Test code is a first class citizen—it deserves testing too
Conclusions                                                                  16


 ■ Mutation testing has a lot to offer teams looking to constantly improve
    the way they do things

 ■ Test code is a first class citizen—it deserves testing too
 ■ Computing power and quality of tooling are improving so mutation
    testing is a realistic tool to use day to day
Conclusions                                                                  16


 ■ Mutation testing has a lot to offer teams looking to constantly improve
    the way they do things

 ■ Test code is a first class citizen—it deserves testing too
 ■ Computing power and quality of tooling are improving so mutation
    testing is a realistic tool to use day to day

 ■ Passing mutation tests run a lot quicker than failing ones, so this
    should only be applied by relatively “mature” development teams
Conclusions                                                                  16


 ■ Mutation testing has a lot to offer teams looking to constantly improve
    the way they do things

 ■ Test code is a first class citizen—it deserves testing too
 ■ Computing power and quality of tooling are improving so mutation
    testing is a realistic tool to use day to day

 ■ Passing mutation tests run a lot quicker than failing ones, so this
    should only be applied by relatively “mature” development teams

 ■ The barrier to entry is low, so you can start doing this today
Links and resources
NinjaTurtles:
http://www.mutation-testing.net
Tests and testability:
http://davidmusgrove.com/blog
Email:
david at davidmusgrove.com




                                  17

Mais conteúdo relacionado

Mais procurados

Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with JunitValerio Maggio
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesNarendra Pathai
 
GeeCON - Improve your tests with Mutation Testing
GeeCON - Improve your tests with Mutation TestingGeeCON - Improve your tests with Mutation Testing
GeeCON - Improve your tests with Mutation TestingNicolas Fränkel
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnitinTwentyEight Minutes
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkHumberto Marchezi
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.xdjberg96
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockitoMathieu Carbou
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 
05 junit
05 junit05 junit
05 junitmha4
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionAlex Su
 

Mais procurados (20)

Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Mutation testing in Java
Mutation testing in JavaMutation testing in Java
Mutation testing in Java
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
GeeCON - Improve your tests with Mutation Testing
GeeCON - Improve your tests with Mutation TestingGeeCON - Improve your tests with Mutation Testing
GeeCON - Improve your tests with Mutation Testing
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnit
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Junit
JunitJunit
Junit
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
05 junit
05 junit05 junit
05 junit
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Junit
JunitJunit
Junit
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 

Destaque

Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014
Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014
Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014lisacrispin
 
Wireless application protocol (WAP)
Wireless application protocol (WAP)Wireless application protocol (WAP)
Wireless application protocol (WAP)Sajan Sahu
 
Automated Penetration Testing With Core Impact
Automated Penetration Testing With Core ImpactAutomated Penetration Testing With Core Impact
Automated Penetration Testing With Core ImpactTom Eston
 
Mutation testing (OOP 2012, 2012-JAN-24)
Mutation testing (OOP 2012, 2012-JAN-24)Mutation testing (OOP 2012, 2012-JAN-24)
Mutation testing (OOP 2012, 2012-JAN-24)Filip Van Laenen
 
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Alex Denisov
 
System testing
System testingSystem testing
System testingSlideshare
 
System testing ppt
System testing pptSystem testing ppt
System testing pptL ESHWAR
 
futuristic trends in information technology
futuristic trends in information technologyfuturistic trends in information technology
futuristic trends in information technologyamartya_kumar
 
Successful Beta Testing
Successful Beta TestingSuccessful Beta Testing
Successful Beta TestingCentercode
 
Black box of Aircraft
Black box of AircraftBlack box of Aircraft
Black box of AircraftSusmit Sircar
 
State of Digital Transformation 2016. Altimeter Report
State of Digital Transformation 2016. Altimeter ReportState of Digital Transformation 2016. Altimeter Report
State of Digital Transformation 2016. Altimeter ReportDen Reymer
 
Information technology ppt
Information technology ppt Information technology ppt
Information technology ppt Babasab Patil
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technologyEldos Kuriakose
 

Destaque (20)

Black box
Black box Black box
Black box
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014
Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014
Advanced Topics in Agile Testing - The Future - Agile Testing Days 2014
 
Wireless application protocol (WAP)
Wireless application protocol (WAP)Wireless application protocol (WAP)
Wireless application protocol (WAP)
 
Automated Penetration Testing With Core Impact
Automated Penetration Testing With Core ImpactAutomated Penetration Testing With Core Impact
Automated Penetration Testing With Core Impact
 
Mobile Computing
Mobile ComputingMobile Computing
Mobile Computing
 
Mutation testing (OOP 2012, 2012-JAN-24)
Mutation testing (OOP 2012, 2012-JAN-24)Mutation testing (OOP 2012, 2012-JAN-24)
Mutation testing (OOP 2012, 2012-JAN-24)
 
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
 
System testing
System testingSystem testing
System testing
 
Black box
Black boxBlack box
Black box
 
System testing ppt
System testing pptSystem testing ppt
System testing ppt
 
futuristic trends in information technology
futuristic trends in information technologyfuturistic trends in information technology
futuristic trends in information technology
 
Successful Beta Testing
Successful Beta TestingSuccessful Beta Testing
Successful Beta Testing
 
Black box of Aircraft
Black box of AircraftBlack box of Aircraft
Black box of Aircraft
 
Black Box
Black BoxBlack Box
Black Box
 
State of Digital Transformation 2016. Altimeter Report
State of Digital Transformation 2016. Altimeter ReportState of Digital Transformation 2016. Altimeter Report
State of Digital Transformation 2016. Altimeter Report
 
Black box
Black boxBlack box
Black box
 
IT ppt
IT pptIT ppt
IT ppt
 
Information technology ppt
Information technology ppt Information technology ppt
Information technology ppt
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technology
 

Semelhante a An introduction to mutation testing

Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDDrubocoptero
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Software Craftsmanship Alicante
 
Best practices for unit testing RxJava
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJavaSimon Percic
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliabilitymcollison
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia岳華 杜
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)vilniusjug
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allHayomeTakele
 
Safe-Commit Analysis to Facilitate Team Software Development
Safe-Commit Analysis to Facilitate Team Software DevelopmentSafe-Commit Analysis to Facilitate Team Software Development
Safe-Commit Analysis to Facilitate Team Software DevelopmentJan Wloka
 
Scjp questions
Scjp questionsScjp questions
Scjp questionsroudhran
 
Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Will Shen
 
Progression by Regression: How to increase your A/B Test Velocity
Progression by Regression: How to increase your A/B Test VelocityProgression by Regression: How to increase your A/B Test Velocity
Progression by Regression: How to increase your A/B Test VelocityStitch Fix Algorithms
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style GuideJacky Lai
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaQA or the Highway
 
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
 
How good are your tests?
How good are your tests?How good are your tests?
How good are your tests?Noam Shaish
 

Semelhante a An introduction to mutation testing (20)

Introducción práctica a TDD
Introducción práctica a TDDIntroducción práctica a TDD
Introducción práctica a TDD
 
Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)Introducción práctica a Test-Driven Development (TDD)
Introducción práctica a Test-Driven Development (TDD)
 
Best practices for unit testing RxJava
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJava
 
des mutants dans le code.pdf
des mutants dans le code.pdfdes mutants dans le code.pdf
des mutants dans le code.pdf
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Pi j4.2 software-reliability
Pi j4.2 software-reliabilityPi j4.2 software-reliability
Pi j4.2 software-reliability
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
 
Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)Developer Tests - Things to Know (Vilnius JUG)
Developer Tests - Things to Know (Vilnius JUG)
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 
Safe-Commit Analysis to Facilitate Team Software Development
Safe-Commit Analysis to Facilitate Team Software DevelopmentSafe-Commit Analysis to Facilitate Team Software Development
Safe-Commit Analysis to Facilitate Team Software Development
 
Scjp questions
Scjp questionsScjp questions
Scjp questions
 
Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)Junit Recipes - Elementary tests (2/2)
Junit Recipes - Elementary tests (2/2)
 
Progression by Regression: How to increase your A/B Test Velocity
Progression by Regression: How to increase your A/B Test VelocityProgression by Regression: How to increase your A/B Test Velocity
Progression by Regression: How to increase your A/B Test Velocity
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
FASTEST: Test Case Generation from Z Specifications
FASTEST: Test Case Generation from Z SpecificationsFASTEST: Test Case Generation from Z Specifications
FASTEST: Test Case Generation from Z Specifications
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David Laulusa
 
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
 
How good are your tests?
How good are your tests?How good are your tests?
How good are your tests?
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Último

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 organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Último (20)

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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

An introduction to mutation testing

  • 1. An introduction to mutation testing 1 David Musgrove Lead developer of NinjaTurtles Author of Tests and testability blog
  • 4. Overview What is mutation testing? How do we do mutation testing? 2
  • 5. Overview What is mutation testing? How do we do mutation testing? Why do we do mutation testing? 2
  • 6. Overview What is mutation testing? How do we do mutation testing? Why do we do mutation testing? What are the disadvantages? 2
  • 7. Overview What is mutation testing? How do we do mutation testing? Why do we do mutation testing? What are the disadvantages? Conclusions 2
  • 8. What is mutation testing? 3
  • 9. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail
  • 10. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail ■ Failing is the new passing—the mutant should break the tests
  • 11. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail ■ Failing is the new passing—the mutant should break the tests ■ The tests collectively should fail, not every individual test
  • 12. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail ■ Failing is the new passing—the mutant should break the tests ■ The tests collectively should fail, not every individual test ■ It indicates how well your code is covered by your suite of tests
  • 13. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail ■ Failing is the new passing—the mutant should break the tests ■ The tests collectively should fail, not every individual test ■ It indicates how well your code is covered by your suite of tests ■ Mutation testing doesn’t test your code, it tests your tests
  • 14. What is mutation testing? 3 ■ It is the technique of running your tests over deliberately broken versions (mutants) of your code to make sure they fail ■ Failing is the new passing—the mutant should break the tests ■ The tests collectively should fail, not every individual test ■ It indicates how well your code is covered by your suite of tests ■ Mutation testing doesn’t test your code, it tests your tests ■ It is not new—the concept was introduced by Richard Lipton in 1971
  • 15. How do we “break” the code? 4
  • 16. How do we “break” the code? 4 ■ Example: swap arithmetic operators +, –, x, ÷, modulo
  • 17. How do we “break” the code? 4 ■ Example: swap arithmetic operators +, –, x, ÷, modulo ■ Errors can be introduced, for example division by zero—but this should just produce a test failure, which is fine
  • 18. How do we “break” the code? 4 ■ Example: swap arithmetic operators +, –, x, ÷, modulo ■ Errors can be introduced, for example division by zero—but this should just produce a test failure, which is fine ■ Example: swap comparison operators ==, !=, <=, <, >=, >
  • 19. How do we “break” the code? 4 ■ Example: swap arithmetic operators +, –, x, ÷, modulo ■ Errors can be introduced, for example division by zero—but this should just produce a test failure, which is fine ■ Example: swap comparison operators ==, !=, <=, <, >=, > ■ Can introduce invariants, for example == and >= can be equivalent checking the upper limit of a loop counter, so handle with care
  • 20. How do we “break” the code? 4 ■ Example: swap arithmetic operators +, –, x, ÷, modulo ■ Errors can be introduced, for example division by zero—but this should just produce a test failure, which is fine ■ Example: swap comparison operators ==, !=, <=, <, >=, > ■ Can introduce invariants, for example == and >= can be equivalent checking the upper limit of a loop counter, so handle with care ■ Example: delete “statements” (e.g. .NET IL sequence points)
  • 22. Then what? 5 ■ We save the mutated code and run the test suite against it
  • 23. Then what? 5 ■ We save the mutated code and run the test suite against it ■ We hope the test suite fails and the mutant is “killed”
  • 24. Then what? 5 ■ We save the mutated code and run the test suite against it ■ We hope the test suite fails and the mutant is “killed” ■ If the mutant survives, then further investigation is necessary
  • 25. Then what? 5 ■ We save the mutated code and run the test suite against it ■ We hope the test suite fails and the mutant is “killed” ■ If the mutant survives, then further investigation is necessary ■ We may have to add tests to kill the mutant
  • 26. Then what? 5 ■ We save the mutated code and run the test suite against it ■ We hope the test suite fails and the mutant is “killed” ■ If the mutant survives, then further investigation is necessary ■ We may have to add tests to kill the mutant ■ We may have to refactor the code to kill the mutant
  • 27. Then what? 5 ■ We save the mutated code and run the test suite against it ■ We hope the test suite fails and the mutant is “killed” ■ If the mutant survives, then further investigation is necessary ■ We may have to add tests to kill the mutant ■ We may have to refactor the code to kill the mutant ■ Both are related to TDD—red, green refactor
  • 28. Can I see an example? 6
  • 29. Can I see an example? 6 ■ Here’s a simple method with a test public int Subtract(int a, int b) { return a – b; } [Test] public void TestSubtract() { Assert.AreEqual(1, Subtract(3, 2)); } Test passes
  • 30. Can I see an example? 6 ■ Here’s a simple method with a test public int Subtract(int a, int b) { return a – b; ■ We’re going to mutate the arithmetic } operator, replacing it with addition and [Test] division public void TestSubtract() { Assert.AreEqual(1, Subtract(3, 2)); } Test passes
  • 31. Can I see an example? 6 ■ Here’s a simple method with a test public int Subtract(int a, int b) { return a + b; ■ We’re going to mutate the arithmetic } operator, replacing it with addition and [Test] division public void TestSubtract() { ■ Let’s try addition: 3 + 2 = 5, so the } Assert.AreEqual(1, Subtract(3, 2)); test fails—which is good Test fails
  • 32. Can I see an example? 6 ■ Here’s a simple method with a test public int Subtract(int a, int b) { return a / b; ■ We’re going to mutate the arithmetic } operator, replacing it with addition and [Test] division public void TestSubtract() { ■ Let’s try addition: 3 + 2 = 5, so the } Assert.AreEqual(1, Subtract(3, 2)); test fails—which is good Test passes ■ Let’s try division: 3 / 2 = 1 (remember, this is integer division), so the test passes—which is bad
  • 33. What does that show us? 7
  • 34. What does that show us? 7 ■ The division mutant survived
  • 35. What does that show us? 7 ■ The division mutant survived ■ The existing test (suite) is inadequate
  • 36. What does that show us? 7 ■ The division mutant survived public int Subtract(int a, int b) { return a – b; ■ The existing test (suite) is inadequate } [Test] ■ We need to improve the test(s)—the public void TestSubtract() current test is far too simplistic with { Assert.AreEqual(1, Subtract(3, 2)); just one simple assertion } Unit test passes Mutation testing fails
  • 37. What does that show us? 7 ■ The division mutant survived public int Subtract(int a, int b) { return a – b; ■ The existing test (suite) is inadequate } [Test] ■ We need to improve the test(s)—the public void TestSubtract() current test is far too simplistic with { Assert.AreEqual(1, Subtract(3, 2)); just one simple assertion } ■ We add a second test assertion Unit test passes Mutation testing fails
  • 38. What does that show us? 7 ■ The division mutant survived public int Subtract(int a, int b) { return a – b; ■ The existing test (suite) is inadequate } ■ We need to improve the test(s)—the [Test] public void TestSubtract() current test is far too simplistic with { Assert.AreEqual(1, Subtract(3, 2)); just one simple assertion Assert.AreEqual(5, Subtract(3, -2)); } ■ We add a second test assertion Unit test passes ■ Here is the fixed test that now kills the Mutation testing passes division mutant
  • 39. How do we do mutation testing? 8
  • 40. How do we do mutation testing? 8 ■ Can be applied at source code, intermediate code (Java ByteCode, Microsoft IL) or compiled code level
  • 41. How do we do mutation testing? 8 ■ Can be applied at source code, intermediate code (Java ByteCode, Microsoft IL) or compiled code level ■ For Java and .NET, intermediate code is easiest to target in an automated solution as it has a relatively small set of well understood instructions and doesn’t require code parsing
  • 42. How do we do mutation testing? 8 ■ Can be applied at source code, intermediate code (Java ByteCode, Microsoft IL) or compiled code level ■ For Java and .NET, intermediate code is easiest to target in an automated solution as it has a relatively small set of well understood instructions and doesn’t require code parsing ■ Can be automated using a mutation testing tool
  • 43. What tools are available? 9
  • 44. What tools are available? 9 ■ There are a number of abortive open source attempts, or skeleton projects; only a few projects are actively maintained and developed
  • 45. What tools are available? 9 ■ There are a number of abortive open source attempts, or skeleton projects; only a few projects are actively maintained and developed ■ The following show signs of meaningful activity within the last six months at the time of writing (August 2012)
  • 46. What tools are available? 9 ■ There are a number of abortive open source attempts, or skeleton projects; only a few projects are actively maintained and developed ■ The following show signs of meaningful activity within the last six months at the time of writing (August 2012) ■ Java ByteCode mutation: PIT, Javalanche
  • 47. What tools are available? 9 ■ There are a number of abortive open source attempts, or skeleton projects; only a few projects are actively maintained and developed ■ The following show signs of meaningful activity within the last six months at the time of writing (August 2012) ■ Java ByteCode mutation: PIT, Javalanche ■ .NET IL: NinjaTurtles
  • 48. Why do we do mutation testing? 10
  • 49. Why do we do mutation testing? 10 ■ I like to think of it as a way of measuring a team’s test-drivenness
  • 50. Why do we do mutation testing? 10 ■ I like to think of it as a way of measuring a team’s test-drivenness ■ Test-driven development (TDD): write test, write code to make it pass, refactor (red, green, refactor)
  • 51. Why do we do mutation testing? 10 ■ I like to think of it as a way of measuring a team’s test-drivenness ■ Test-driven development (TDD): write test, write code to make it pass, refactor (red, green, refactor) ■ No code should be written that isn’t there to make a test pass
  • 52. Why do we do mutation testing? 10 ■ I like to think of it as a way of measuring a team’s test-drivenness ■ Test-driven development (TDD): write test, write code to make it pass, refactor (red, green, refactor) ■ No code should be written that isn’t there to make a test pass ■ Therefore if you mutate any code you should make a test fail
  • 53. Why do we do mutation testing? 10 ■ I like to think of it as a way of measuring a team’s test-drivenness ■ Test-driven development (TDD): write test, write code to make it pass, refactor (red, green, refactor) ■ No code should be written that isn’t there to make a test pass ■ Therefore if you mutate any code you should make a test fail ■ So perfect TDD implies 100% of (meaningful) mutants killed
  • 55. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users
  • 56. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users ■ Level 1: code is tested by dedicated testers before release
  • 57. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users ■ Level 1: code is tested by dedicated testers before release ■ Level 2: code is also tested by the developers; some automation
  • 58. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users ■ Level 1: code is tested by dedicated testers before release ■ Level 2: code is also tested by the developers; some automation ■ Level 3: tests are written first and automated as far as is possible
  • 59. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users ■ Level 1: code is tested by dedicated testers before release ■ Level 2: code is also tested by the developers; some automation ■ Level 3: tests are written first and automated as far as is possible ■ Level 4: mutation testing is applied to verify efficacy of test suites
  • 60. YAMM—yet another maturity model 11 ■ Level 0: code is tested when it is released, by the users ■ Level 1: code is tested by dedicated testers before release ■ Level 2: code is also tested by the developers; some automation ■ Level 3: tests are written first and automated as far as is possible ■ Level 4: mutation testing is applied to verify efficacy of test suites ■ This could be a tree, with other ideas like BDD introduced, but it illustrates the position of mutation testing
  • 61. What are the disadvantages? 12
  • 62. What are the disadvantages? 12 ■ Good tooling is only just emerging
  • 63. What are the disadvantages? 12 ■ Good tooling is only just emerging ■ It’s relatively slow and computationally expensive
  • 64. What are the disadvantages? 12 ■ Good tooling is only just emerging ■ It’s relatively slow and computationally expensive ■ Each line of code can produce many mutants
  • 65. What are the disadvantages? 12 ■ Good tooling is only just emerging ■ It’s relatively slow and computationally expensive ■ Each line of code can produce many mutants ■ Each mutant requires a suite of tests to be run
  • 66. What are the disadvantages? 12 ■ Good tooling is only just emerging ■ It’s relatively slow and computationally expensive ■ Each line of code can produce many mutants ■ Each mutant requires a suite of tests to be run ■ But the suite of tests can be narrowed down, and it only needs to be run until the first failure is encountered
  • 67. What are the disadvantages? 12 ■ Good tooling is only just emerging ■ It’s relatively slow and computationally expensive ■ Each line of code can produce many mutants ■ Each mutant requires a suite of tests to be run ■ But the suite of tests can be narrowed down, and it only needs to be run until the first failure is encountered ■ And it’s eminently parallelisable for multicore PCs
  • 68. What are the disadvantages? 13
  • 69. What are the disadvantages? 13 ■ A passing mutation test can fail fast, but a failing mutation test is likely to take significantly longer as it runs the entire set of relevant tests
  • 70. What are the disadvantages? 13 ■ A passing mutation test can fail fast, but a failing mutation test is likely to take significantly longer as it runs the entire set of relevant tests ■ So should be applied continuously to keep quality high
  • 71. What are the disadvantages? 13 ■ A passing mutation test can fail fast, but a failing mutation test is likely to take significantly longer as it runs the entire set of relevant tests ■ So should be applied continuously to keep quality high ■ Can only realistically be applied in this way to code bases and test suites that are already in fairly good shape
  • 72. A shameless plug for NinjaTurtles 14
  • 73. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased
  • 74. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased ■ Open source tool working at a .NET IL level
  • 75. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased ■ Open source tool working at a .NET IL level ■ Includes seven different types of mutation at time of writing
  • 76. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased ■ Open source tool working at a .NET IL level ■ Includes seven different types of mutation at time of writing ■ Compatible with existing .NET languages and unit test frameworks
  • 77. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased ■ Open source tool working at a .NET IL level ■ Includes seven different types of mutation at time of writing ■ Compatible with existing .NET languages and unit test frameworks ■ Optimisations include parallelised test runs, reduced test suites, fail fast (where the underlying test runner supports it)
  • 78. A shameless plug for NinjaTurtles 14 ■ Disclaimer: I’m the lead developer on this so I’m biased ■ Open source tool working at a .NET IL level ■ Includes seven different types of mutation at time of writing ■ Compatible with existing .NET languages and unit test frameworks ■ Optimisations include parallelised test runs, reduced test suites, fail fast (where the underlying test runner supports it) ■ Console runner gives immediate results
  • 80. Sample NinjaTurtles output 15 ■ Simple console command applied to one class within the NinjaTurtles code base
  • 81. Sample NinjaTurtles output 15 ■ Simple console command applied to one class within the NinjaTurtles code base ■ Over 1,000 runs of the test suite, each run as a separate process
  • 82. Sample NinjaTurtles output 15 ■ Simple console command applied to one class within the NinjaTurtles code base ■ Over 1,000 runs of the test suite, each run as a separate process ■ Test results returned in under 90 seconds
  • 83. Sample NinjaTurtles output 15 ■ Simple console command applied to one class within the NinjaTurtles code base ■ Over 1,000 runs of the test suite, each run as a separate process ■ Test results returned in under 90 seconds ■ Also XML or HTML output
  • 85. Conclusions 16 ■ Mutation testing has a lot to offer teams looking to constantly improve the way they do things
  • 86. Conclusions 16 ■ Mutation testing has a lot to offer teams looking to constantly improve the way they do things ■ Test code is a first class citizen—it deserves testing too
  • 87. Conclusions 16 ■ Mutation testing has a lot to offer teams looking to constantly improve the way they do things ■ Test code is a first class citizen—it deserves testing too ■ Computing power and quality of tooling are improving so mutation testing is a realistic tool to use day to day
  • 88. Conclusions 16 ■ Mutation testing has a lot to offer teams looking to constantly improve the way they do things ■ Test code is a first class citizen—it deserves testing too ■ Computing power and quality of tooling are improving so mutation testing is a realistic tool to use day to day ■ Passing mutation tests run a lot quicker than failing ones, so this should only be applied by relatively “mature” development teams
  • 89. Conclusions 16 ■ Mutation testing has a lot to offer teams looking to constantly improve the way they do things ■ Test code is a first class citizen—it deserves testing too ■ Computing power and quality of tooling are improving so mutation testing is a realistic tool to use day to day ■ Passing mutation tests run a lot quicker than failing ones, so this should only be applied by relatively “mature” development teams ■ The barrier to entry is low, so you can start doing this today
  • 90. Links and resources NinjaTurtles: http://www.mutation-testing.net Tests and testability: http://davidmusgrove.com/blog Email: david at davidmusgrove.com 17

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n