Mutation testing (OOP 2012, 2012-JAN-24)

Filip Van Laenen
Filip Van LaenenSjefsarkitekt/Chief Architect at Computas AS
Mutation Testing


   Filip van Laenen
       OOP 2012
      2012-01-24



                      © Computas AS 27.01.12
Agenda


•   Basics of mutation testing
•   Relation to other testing techniques
•   Example
•   Mutation testing techniques
•   Mutation testing tools
•   Personal experiences and recommendations
•   Improvements
•   Questions and comments



                         2                © Computas AS 27.01.12
Basics of
Mutation Testing




       3           © Computas AS 27.01.12
Mutation Testing in a Nutshell




   Seeking The Summoner @ The Daily WTF
   http://thedailywtf.com/Articles/Seeking-The-Summoner.aspx

                                                     4         © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        5                 © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        6                 © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)


• Unit tests guard the source code
• But who guards the guardians?
   • Do the unit tests cover all source code?
      • Lines?
      • Branches?
      • Paths?
   • Do the unit tests test the right things?

    Mutation testing tests the tests!

                         7                  © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        8                 © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        9                 © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        10                © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        11                © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        12                © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        13                © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)


def max(a, b) {
   return (a < b) ? b : a;
}



def max(a, b) {
   return (a ≤ b) ? b : a;
}


                        14                © Computas AS 27.01.12
Mutation Testing in a Nutshell (cont'd)




                        15                © Computas AS 27.01.12
Does Mutation Testing Work?




“ In practice, if the software contains a
    fault, there will usually be a set of
 mutants that can only be killed by a test
     case that also detects that fault.
 Geist et. al., “Estimation and Enhancement of Real-time
    Software Reliability through Mutation Analysis,” 1992




                           16                    © Computas AS 27.01.12
Does Mutation Testing Work? (cont'd)




“ Complex faults are coupled to simple
 faults in such a way that a test data set
that detects all simple faults in a program
     will detect most complex faults.
   K. Wah, “Fault Coupling in Finite Bijective Functions,”
                                                      1995




                           17                     © Computas AS 27.01.12
Does Mutation Testing Work? (cont'd)


• “Generated mutants are similar to real faults.”
  • Andrews, Briand, Labiche, ICSE 2005
• “Mutation testing is more powerful than
  statement or branch coverage.”
  • Walsh, Ph.D. Thesis, State University of New York at
    Binghampton, 1985
• “Mutation testing is superior to data flow
  coverage criteria.”
  • Frankl, Weiss, Hu, Journal of Systems and Software,
    1997


                           18                    © Computas AS 27.01.12
Relation to Other
Testing Techniques




        19           © Computas AS 27.01.12
Relation to Other Testing Techniques


•   Unit tests
•   Test-Driven Development (TDD)
•   Test coverage
•   Static code analysis
•   Fuzz testing




                         20            © Computas AS 27.01.12
Relation to Other Testing Techniques




                       21              © Computas AS 27.01.12
Is Mutation Testing New?


• R. Lipton, “Fault Diagnosis of Computer
  Programs,” 1971
• R. Lipton et. al., “Hints on Test Data Selection:
  Help for the Practicing Programmer,” 1978
• Historical obstacles:
   • No unit testing
   • No TDD
   • Time-consuming
   • No integration with IDEs


                         22                  © Computas AS 27.01.12
Practical Example
of Mutation Testing




         23           © Computas AS 27.01.12
Practical Example


# Returns the maximum of a.
# @param a An array of integers.
def max(a) {
   return …;
}




                    24             © Computas AS 27.01.12
Practical Example (cont'd)


Omitted: max(null)
Omitted: max([])

def max(a) {
   return …;
}




                       25    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0

def max(a) {
   return 0;
}




                       26    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1

def max(a) {
   return 0;
}




                       27    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1

def max(a) {
   return a.first;
}




                       28    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   return a.first;
}




                       29    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
                        nit t ests!
   m ← a.first;        U             age!
                               cover
   foreach (e ∈ a)        line
                    100%               age?
      if (e > m)                  over
                            nch c
         m ← e;
                   100% b ra
   return m;
}
                       30              © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   m ← a.first;
   foreach (e ∈ a)
      if (e > m)
         m ← e;
   return m;
}
                       31    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   m ← a.first;
   foreach (e ∈ a)
      if (true)
         m ← e;
   return m;
}
                       32    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   return a.last;
}




                       33    © Computas AS 27.01.12
Practical Example (cont'd)


Assertion:    max([0]) = 0
Assertion:    max([1]) = 1
Assertion:    max([1, 2]) = 2
Assertion:    max([2, 1]) = 2

def max(a) {
   return a.last;
}



                       34       © Computas AS 27.01.12
Practical Example (cont'd)


Assertion:    max([0]) = 0
Assertion:    max([1]) = 1
Assertion:    max([1, 2]) = 2
Assertion:    max([2, 1]) = 2

def max(a) {
   m ← a.first;
   foreach (e ∈ a)
      if (e > m)
         m ← e;
   return m;
}                      35       © Computas AS 27.01.12
Practical Example (cont'd)


Assertion:    max([0]) = 0
Assertion:    max([1]) = 1
Assertion:    max([1, 2]) = 2
Assertion:    max([2, 1]) = 2

def max(a) {
   m ← -∞;
   foreach (e ∈ a)
      if (e > m)
         m ← e;
   return m;
}                      36       © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   m ← a.first;
   foreach (e ∈ a)
      if (e > m)   ← Implicit else-branch!
         m ← e;
   return m;
}
                       37           © Computas AS 27.01.12
Practical Example (cont'd)


Assertion: max([0]) = 0
Assertion: max([1]) = 1
Assertion: max([1, 2]) = 2

def max(a) {
   m ← -∞;
   foreach (e ∈ a)                       ?
                                     rage
      if (e > m)               h cove
                   ← Implicitcelse-branch!
                           ran
         m ← e;    10 0% b
   return m;
}
                       38           © Computas AS 27.01.12
Practical Example (cont'd)


• 100% test coverage may be illusory
   • Line coverage
   • Branch coverage
   • Path coverage
• TDD principles easily broken
   • Even if you're very careful




                        39             © Computas AS 27.01.12
Mutation Testing
  Techniques




       40          © Computas AS 27.01.12
Mutation Testing Techniques


• Three aspects:
   • Mutation injection
   • Mutation types
   • Unit test selection per mutant
• Key properties:
   • Efficiency
   • Performance




                        41            © Computas AS 27.01.12
Mutation Injection


• Source code mutation
• Binary code mutation
• Caveats:
   • De-mutation
   • Compilation errors
   • Invalid binary code




                           42   © Computas AS 27.01.12
Mutation Types


• Some mutations never change behaviour
   • Constants reused by unit tests
   • Log messages
• Some mutations can change behaviour
   • Switching between < and ≠
   • Switching between < and ≤
• Some mutations always change behaviour
   • Switching between < and ≥



                      43                   © Computas AS 27.01.12
Mutation Types (cont'd)


def max(a, b) {
   return (a < b) ? b : a;
}

def max(a, b) {
   return (a ≤ b) ? b : a;
}

def max(a, b) {
   return (a ≥ b) ? b : a;
}
                          44   © Computas AS 27.01.12
Mutation Types (cont'd)


for (i ← 0; i < 10; i++) …


for (i ← 0; i ≠ 10; i++) …


for (i ← 0; i ≥ 10; i++) …




                          45   © Computas AS 27.01.12
Mutation Types Guaranteed to Change
Behaviour *

• Negation of the comparison
   • Switching between = and ≠
   • Switching between < and ≥
   • Switching between > and ≤
• Negation of boolean conditions
   • Adding a ¬, ! or ~
• Shortcutting boolean conditions
   • Replacement with True or False



                       46             © Computas AS 27.01.12
Unit Test Selection


• Goal: find the unit test that “kills” the mutant
• Selection aids:
   • Hints
   • Name/package matching
   • Code coverage tools
   • Automatic learning
   • Other heuristics




                         47                 © Computas AS 27.01.12
Unit Test Selection (cont'd)


• System:
   • 50 classes
   • 20 unit tests per class
   • 1 ms per unit test
   • Unit testing time: 50 × 20 × 1ms = 1s
• 10 mutants per class:
   • Brute-force: 10 × 50 × 1s = 6m 20s
   • Educated: 10 × 50 × 20 × 1ms = 10s


                         48                  © Computas AS 27.01.12
Unit Test Selection (cont'd)


• System:
   • 500 classes
   • 20 unit tests per class
   • 1 ms per unit test
   • Unit testing time: 500 × 20 × 1ms = 10s
• 10 mutants per class:
   • Brute-force: 10 × 500 × 10s = 13h 53m 20s
   • Educated: 10 × 500 × 20 × 1ms = 1m 40s


                        49                 © Computas AS 27.01.12
Complexity


•   f: Number of function points
•   φ: Number of function points per class, ≥ 1
•   τ: Number of unit tests per function point, ≥ 1
•   μ: Number of mutants per function point, ≥ 1

• Brute-force: (f × τ) × (f × μ) = τ × μ × f²
• Educated force: τ × μ × φ × f
• Ideal: τ × μ × f


                           50                   © Computas AS 27.01.12
Complexity (cont'd)


•   c: Number of classes
•   φ: Number of function points per class, ≥ 1
•   τ: Number of unit tests per function point, ≥ 1
•   μ: Number of mutants per function point, ≥ 1

• Brute-force: (f × τ) × (f × μ) = τ × μ × φ² × c²
• Educated force: τ × μ × φ² × c
• Ideal: τ × μ × φ × c


                           51                 © Computas AS 27.01.12
Loops


for (i ← 0; i < 10; i++) …


for (i ← 0; i < 10; i--) …




                  52         © Computas AS 27.01.12
Infinite Loops


• Terminate mutants that take too long to run
   • What's too long?
• Ruins the performance
• Can be hard to predict




                        53                © Computas AS 27.01.12
Other Problems


• Recursion:
   • Stack overflows
   • Out of memory exceptions
• Syntax errors
• Segmentation faults




                       54       © Computas AS 27.01.12
Mutation Testing
     Tools




       55          © Computas AS 27.01.12
Mutation Testing Tools


• Ruby: Heckle
• Java:
   • Jester
   • Jumble
   • PIT
• C#: Nester
• Python: Pester




                         56   © Computas AS 27.01.12
Heckle


•   Ruby
•   Test::Unit and rSpec
•   Usually run from the command-line
•   Runs a set of unit tests on a class or a method
•   Good to-the-point reporting
•   Good performance
•   Virtually no documentation

• http://rubyforge.org/projects/seattlerb/
• http://docs.seattlerb.org/heckle/

                           57                 © Computas AS 27.01.12
Heckle Mutations


•   Booleans
•   Numbers
•   Strings
•   Symbols
•   Ranges
•   Regexes
•   Branches (if, while, unless, until)




                           58             © Computas AS 27.01.12
Heckle Sample Output


Initial tests pass. Let's rumble.
*****************************************************************
*** Greeter#greet loaded with 3 possible mutations
*****************************************************************

3 mutations remaining...
2 mutations remaining...
1 mutations remaining...
No mutants survived. Cool!




                                59                       © Computas AS 27.01.12
My Heckle Sample Output


filip@filip-laptop:~/github/wruf$ rake heckle
(in /home/filip/github/wruf)
Doing mutation testing on 15 method(s) of FlickrSearcher against
test/flickr_searcher_unit_test.rb:
 o FlickrSearcher#convert_photo_info [1/15]
 o FlickrSearcher#create_form_data_to_get_info_about_photo [2/15]
 o FlickrSearcher#create_form_data_to_get_info_about_user [3/15]
 o FlickrSearcher#create_form_data_to_search_photos [4/15]
 o FlickrSearcher#do_rest_request [5/15]
 o FlickrSearcher#get_author [6/15]
…
 o FlickrSearcher#get_photo_info [12/15]
 o FlickrSearcher#get_photo_url [13/15]
 o FlickrSearcher#get_ref_url [14/15]
 o FlickrSearcher#get_ref_url_from_xml_photo_info [15/15]
Checked 192 mutations, and no issues were found in FlickrSearcher.



                                60                       © Computas AS 27.01.12
My Heckle Sample Output (cont'd)


Doing mutation testing on 7 method(s) of WrufSettings against
test/wruf_settings_unit_test.rb:
 o WrufSettings#dimensions [1/7]
 o WrufSettings#dimensions= [2/7]
 o WrufSettings#hours [3/7]
 o WrufSettings#hours= [4/7]
 o WrufSettings#tags [5/7]
 o WrufSettings#tolerance [6/7]
 o WrufSettings#tolerance= [7/7]
Checked 0 mutations, and no issues were found in WrufSettings.




                                61                       © Computas AS 27.01.12
Heckle Sample Report


--- original
+++ mutation
 def calculate_precision(rescaled_number)
   if (rescaled_number < 9.995) then
     return 2
   else
     if (rescaled_number < 99.95) then
       return 1
     else
       if (rescaled_number >= 99.95) then
         return 0
       else
-        return -1
+        return -70
       end
     end
   end
 end
                                62          © Computas AS 27.01.12
Jester


• Java
• JUnit
• Usually run from the command-line
   • Grester for Maven2
• Operates on source code
• Runs all unit tests on all classes
• Reporting and documentation could be better

• http://jester.sourceforge.net/
• http://sourceforge.net/projects/grester/
                       63                © Computas AS 27.01.12
Jester Sample Report Overview




                     64         © Computas AS 27.01.12
Jester Sample Detailed Report




                      65        © Computas AS 27.01.12
Pester and Nester


• Pester
   • Jester for Python
   • PyUnit
• Nester
   • Port of Jester for C#
   • NUnit
   • Integrated with Visual Studio
   • But outdated…
   • http://nester.sourceforge.net/

                        66            © Computas AS 27.01.12
Nester Sample Report




                       67   © Computas AS 27.01.12
Jumble


•   Java
•   JUnit
•   Run from the command-line
•   Operates on byte code
•   Runs unit tests on a class
•   Reporting and documentation could be better
•   Claims to be faster than Jester

• http://jumble.sourceforge.net/index.html

                         68                © Computas AS 27.01.12
Jumble Sample Report


Mutating Foo
Tests: FooTest
Mutation points   = 12, unit test time limit 2.02s
..
M FAIL: Foo:31:   negated conditional
M FAIL: Foo:33:   negated conditional
M FAIL: Foo:34:   - -> +
M FAIL: Foo:35:   negated conditional
......
Score: 67%




                           69                  © Computas AS 27.01.12
PIT


• Java
• JUnit
• Maven or command-line
• Operates on byte code
• Large set of mutators
   • Also possibly equivalent mutators available
• Highly configurable
• Sensible defaults

• http://pitest.org/
                         70                 © Computas AS 27.01.12
PIT Mutators


•   Conditionals Boundary
•   Negate Conditionals
•   Math
•   Increments
•   Invert Negatives
•   Inline Constant*
•   Return Values
•   Void Method Call
•   Non Void Method Call*
•   Constructor Call*

                            71   © Computas AS 27.01.12
PIT Sample Report




                    72   © Computas AS 27.01.12
Personal Experiences
and Recommendations




          73            © Computas AS 27.01.12
Experiences and Recommendations


• Use mutation testing from day 1
   • Start on a small code base
• Keep number of unit tests per class low
   • Have small classes
• Select a good tool
   • Configurable
   • Flexible
   • One that can output the mutant


                        74                  © Computas AS 27.01.12
Experiences and Recommendations
(cont'd)

• Believe the tool
   • Or try to proof that the tool is wrong
• Fix the problem
   • Don't turn mutation testing off
• Embrace the “more than 100%” test coverage
   • Path coverage
   • Less code
   • More unit tests
   • More intelligent unit tests

                      75                © Computas AS 27.01.12
Improvements




     76        © Computas AS 27.01.12
Improvements


• Integration with more unit testing frameworks
• Better unit test–source code mapping
   • Better heuristics
• Parallellisation
• Better reporting
• IDE integration
• Building tool integration




                        77                © Computas AS 27.01.12
The Ideal Mutation Testing Tool™


•   Easy integration with building tools
•   Easy integration with IDEs
•   Support for all unit testing frameworks
•   Human-aided unit test selection heuristics
•   Full parallellisation
•   Good source code mutation reporting




                          78                 © Computas AS 27.01.12
Questions?




Contact:

    fvl@computas.com               @filipvanlaenen

    Computas AS                    Tel +47-67 83 10 00
    Lysaker Torg 45, pb 482        Fax +47-67 83 10 01
    N-1327 Lysaker                 Org.nr: NO 986 352 325 MVA
    NORWAY                         www.computas.com


                              79                      © Computas AS 27.01.12
1 of 79

Recommended

Kill the mutants - A better way to test your tests by
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
9K views55 slides
Integration Patterns for Microservices Architectures by
Integration Patterns for Microservices ArchitecturesIntegration Patterns for Microservices Architectures
Integration Patterns for Microservices ArchitecturesNATS
433 views29 slides
EC2でNginxを使ってみよう JAWS大阪第9回勉強会資料 by
EC2でNginxを使ってみよう JAWS大阪第9回勉強会資料EC2でNginxを使ってみよう JAWS大阪第9回勉強会資料
EC2でNginxを使ってみよう JAWS大阪第9回勉強会資料Masahiro Haraoka
4.3K views40 slides
Réduire la dette émotionnelle dans une équipe Scrum by
Réduire la dette émotionnelle dans une équipe ScrumRéduire la dette émotionnelle dans une équipe Scrum
Réduire la dette émotionnelle dans une équipe ScrumMarilyn Kol
1.6K views29 slides
ふつうのRailsアプリケーション開発 by
ふつうのRailsアプリケーション開発ふつうのRailsアプリケーション開発
ふつうのRailsアプリケーション開発Takafumi ONAKA
30.8K views90 slides
テストコード入門 by
テストコード入門テストコード入門
テストコード入門小川 昌吾
25.1K views45 slides

More Related Content

What's hot

PostgreSQLセキュリティ総復習 by
PostgreSQLセキュリティ総復習PostgreSQLセキュリティ総復習
PostgreSQLセキュリティ総復習Uptime Technologies LLC (JP)
13.1K views51 slides
今さら聞けないasteria warp運用の基礎 ファイナル by
今さら聞けないasteria warp運用の基礎 ファイナル今さら聞けないasteria warp運用の基礎 ファイナル
今さら聞けないasteria warp運用の基礎 ファイナルASTERIA User Group
4K views36 slides
AzureでLaravel動かしてみた by
AzureでLaravel動かしてみたAzureでLaravel動かしてみた
AzureでLaravel動かしてみたKeiji Kamebuchi
4.9K views17 slides
探索ってどういうこと? by
探索ってどういうこと?探索ってどういうこと?
探索ってどういうこと?tef-do
13.3K views37 slides
Java → Kotlin 変換 そのあとに。 by
Java → Kotlin 変換 そのあとに。Java → Kotlin 変換 そのあとに。
Java → Kotlin 変換 そのあとに。健一 辰濱
8.3K views51 slides
Getting a grip on your code dependencies by
Getting a grip on your code dependenciesGetting a grip on your code dependencies
Getting a grip on your code dependenciesDennis Doomen
92 views38 slides

What's hot(20)

今さら聞けないasteria warp運用の基礎 ファイナル by ASTERIA User Group
今さら聞けないasteria warp運用の基礎 ファイナル今さら聞けないasteria warp運用の基礎 ファイナル
今さら聞けないasteria warp運用の基礎 ファイナル
AzureでLaravel動かしてみた by Keiji Kamebuchi
AzureでLaravel動かしてみたAzureでLaravel動かしてみた
AzureでLaravel動かしてみた
Keiji Kamebuchi4.9K views
探索ってどういうこと? by tef-do
探索ってどういうこと?探索ってどういうこと?
探索ってどういうこと?
tef-do13.3K views
Java → Kotlin 変換 そのあとに。 by 健一 辰濱
Java → Kotlin 変換 そのあとに。Java → Kotlin 変換 そのあとに。
Java → Kotlin 変換 そのあとに。
健一 辰濱8.3K views
Getting a grip on your code dependencies by Dennis Doomen
Getting a grip on your code dependenciesGetting a grip on your code dependencies
Getting a grip on your code dependencies
Dennis Doomen92 views
Cloud Ubuntu Open Stack, Juju, MaaS - Ua Deck Nov 2013 by The World Bank
Cloud Ubuntu Open Stack, Juju, MaaS - Ua Deck Nov 2013Cloud Ubuntu Open Stack, Juju, MaaS - Ua Deck Nov 2013
Cloud Ubuntu Open Stack, Juju, MaaS - Ua Deck Nov 2013
The World Bank1.5K views
TestNG Session presented in Xebia XKE by Abhishek Yadav
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
Abhishek Yadav503 views
大規模フロントエンドのクリーンアーキテクチャ化 ~ 年間売上1,000億円企業モノタロウの取組み ~ by 株式会社MonotaRO Tech Team
大規模フロントエンドのクリーンアーキテクチャ化 ~ 年間売上1,000億円企業モノタロウの取組み ~大規模フロントエンドのクリーンアーキテクチャ化 ~ 年間売上1,000億円企業モノタロウの取組み ~
大規模フロントエンドのクリーンアーキテクチャ化 ~ 年間売上1,000億円企業モノタロウの取組み ~
SAP Inside Track Berlin 2018 - DevOps in ABAP Landscapes by Sascha Junkert
SAP Inside Track Berlin 2018 - DevOps in ABAP LandscapesSAP Inside Track Berlin 2018 - DevOps in ABAP Landscapes
SAP Inside Track Berlin 2018 - DevOps in ABAP Landscapes
Sascha Junkert667 views
Shift Left Testing: Going Beyond Agile by TechWell
Shift Left Testing: Going Beyond AgileShift Left Testing: Going Beyond Agile
Shift Left Testing: Going Beyond Agile
TechWell1.1K views
5分でわかるクリーンアーキテクチャ by Kenji Tanaka
5分でわかるクリーンアーキテクチャ5分でわかるクリーンアーキテクチャ
5分でわかるクリーンアーキテクチャ
Kenji Tanaka19.5K views
CI/CDツール比較してみた by Shoya Kai
CI/CDツール比較してみたCI/CDツール比較してみた
CI/CDツール比較してみた
Shoya Kai591 views
Software design as a cooperative game with EventStorming by Alberto Brandolini
Software design as a cooperative game with EventStormingSoftware design as a cooperative game with EventStorming
Software design as a cooperative game with EventStorming
Alberto Brandolini2.2K views
[DO02] Jenkins PipelineとBlue Oceanによる、フルスクラッチからの継続的デリバリ by de:code 2017
[DO02] Jenkins PipelineとBlue Oceanによる、フルスクラッチからの継続的デリバリ[DO02] Jenkins PipelineとBlue Oceanによる、フルスクラッチからの継続的デリバリ
[DO02] Jenkins PipelineとBlue Oceanによる、フルスクラッチからの継続的デリバリ
de:code 20176.6K views
ぼくらが体験入社にこだわるワケ by Daisuke Sato
ぼくらが体験入社にこだわるワケぼくらが体験入社にこだわるワケ
ぼくらが体験入社にこだわるワケ
Daisuke Sato834 views
Goの時刻に関するテスト by Kentaro Kawano
Goの時刻に関するテストGoの時刻に関するテスト
Goの時刻に関するテスト
Kentaro Kawano3.2K views
Managing Infrastructure as a Product - Introduction to Platform Engineering by Adityo Pratomo
Managing Infrastructure as a Product - Introduction to Platform EngineeringManaging Infrastructure as a Product - Introduction to Platform Engineering
Managing Infrastructure as a Product - Introduction to Platform Engineering
Adityo Pratomo242 views
ASTERIA WARP開発前に知っておくべき10の鉄則(AUG関西支部編) by ASTERIA User Group
ASTERIA WARP開発前に知っておくべき10の鉄則(AUG関西支部編)ASTERIA WARP開発前に知っておくべき10の鉄則(AUG関西支部編)
ASTERIA WARP開発前に知っておくべき10の鉄則(AUG関西支部編)
ASTERIA User Group4.5K views
C++でテスト駆動開発 by Akineko Shimizu
C++でテスト駆動開発C++でテスト駆動開発
C++でテスト駆動開発
Akineko Shimizu11.5K views

Viewers also liked

Mutation Testing by
Mutation TestingMutation Testing
Mutation TestingESUG
10K views45 slides
Mutation Testing: Leaving the Stone Age. FOSDEM 2017 by
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Alex Denisov
618 views75 slides
Exploratory Testing Explained and Experienced by
Exploratory Testing Explained and ExperiencedExploratory Testing Explained and Experienced
Exploratory Testing Explained and ExperiencedMaaret Pyhäjärvi
5K views17 slides
A Taste of Exploratory Testing by
A Taste of Exploratory TestingA Taste of Exploratory Testing
A Taste of Exploratory TestingAnne-Marie Charrett
3.1K views35 slides
An introduction to mutation testing by
An introduction to mutation testingAn introduction to mutation testing
An introduction to mutation testingdavidmus
2K views90 slides
Black box by
Black box Black box
Black box Saurav Jha
898 views9 slides

Viewers also liked(17)

Mutation Testing by ESUG
Mutation TestingMutation Testing
Mutation Testing
ESUG10K views
Mutation Testing: Leaving the Stone Age. FOSDEM 2017 by Alex Denisov
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Alex Denisov618 views
An introduction to mutation testing by davidmus
An introduction to mutation testingAn introduction to mutation testing
An introduction to mutation testing
davidmus2K views
Black box by Saurav Jha
Black box Black box
Black box
Saurav Jha898 views
Exploratory Testing by sriks7
Exploratory TestingExploratory Testing
Exploratory Testing
sriks710.7K views
How to Use Social Media to Identify Better Search Keywords by Kelsey Jones
How to Use Social Media to Identify Better Search KeywordsHow to Use Social Media to Identify Better Search Keywords
How to Use Social Media to Identify Better Search Keywords
Kelsey Jones1.1K views
Exploratory Testing in Agile by codecentric AG
Exploratory Testing in AgileExploratory Testing in Agile
Exploratory Testing in Agile
codecentric AG11.3K views
System testing by Slideshare
System testingSystem testing
System testing
Slideshare6.9K views
Black box by Sajan Sahu
Black boxBlack box
Black box
Sajan Sahu3.7K views
System testing ppt by L ESHWAR
System testing pptSystem testing ppt
System testing ppt
L ESHWAR22.9K views
Successful Beta Testing by Centercode
Successful Beta TestingSuccessful Beta Testing
Successful Beta Testing
Centercode68.5K views
Black box of Aircraft by Susmit Sircar
Black box of AircraftBlack box of Aircraft
Black box of Aircraft
Susmit Sircar8.6K views
Black box by fadysid03
Black boxBlack box
Black box
fadysid0332.2K views

Similar to Mutation testing (OOP 2012, 2012-JAN-24)

Oop 2015 – Mutation Testing by
Oop 2015 – Mutation TestingOop 2015 – Mutation Testing
Oop 2015 – Mutation TestingFilip Van Laenen
1.1K views62 slides
Sudarshana Hore_2015 Intern MISO by
Sudarshana Hore_2015 Intern MISOSudarshana Hore_2015 Intern MISO
Sudarshana Hore_2015 Intern MISOSudarshana Hore
407 views40 slides
Mutation Testing with PIT (Booster 2014, 2014-MAR-13) by
Mutation Testing with PIT (Booster 2014, 2014-MAR-13)Mutation Testing with PIT (Booster 2014, 2014-MAR-13)
Mutation Testing with PIT (Booster 2014, 2014-MAR-13)Filip Van Laenen
1.5K views62 slides
Mit2 72s09 lec02 (1) by
Mit2 72s09 lec02 (1)Mit2 72s09 lec02 (1)
Mit2 72s09 lec02 (1)Jasim Almuhandis
67 views41 slides
Converted ansys f by
Converted ansys fConverted ansys f
Converted ansys fVarsha Patil
423 views63 slides
Mixed Integer Programming: Analyzing 12 Years of Progress by
Mixed Integer Programming: Analyzing 12 Years of ProgressMixed Integer Programming: Analyzing 12 Years of Progress
Mixed Integer Programming: Analyzing 12 Years of ProgressIBM Decision Optimization
1.9K views32 slides

Similar to Mutation testing (OOP 2012, 2012-JAN-24)(20)

Sudarshana Hore_2015 Intern MISO by Sudarshana Hore
Sudarshana Hore_2015 Intern MISOSudarshana Hore_2015 Intern MISO
Sudarshana Hore_2015 Intern MISO
Sudarshana Hore407 views
Mutation Testing with PIT (Booster 2014, 2014-MAR-13) by Filip Van Laenen
Mutation Testing with PIT (Booster 2014, 2014-MAR-13)Mutation Testing with PIT (Booster 2014, 2014-MAR-13)
Mutation Testing with PIT (Booster 2014, 2014-MAR-13)
Filip Van Laenen1.5K views
System Verilog 2009 & 2012 enhancements by Subash John
System Verilog 2009 & 2012 enhancementsSystem Verilog 2009 & 2012 enhancements
System Verilog 2009 & 2012 enhancements
Subash John4.4K views
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1) by Agile Lietuva
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Agile Lietuva715 views
Dependable Systems - Structure-Based Dependabiilty Modeling (6/16) by Peter Tröger
Dependable Systems - Structure-Based Dependabiilty Modeling (6/16)Dependable Systems - Structure-Based Dependabiilty Modeling (6/16)
Dependable Systems - Structure-Based Dependabiilty Modeling (6/16)
Peter Tröger2K views
Formal Verification of Developer Tests: a Research Agenda Inspired by Mutatio... by University of Antwerp
Formal Verification of Developer Tests: a Research Agenda Inspired by Mutatio...Formal Verification of Developer Tests: a Research Agenda Inspired by Mutatio...
Formal Verification of Developer Tests: a Research Agenda Inspired by Mutatio...
Sampling-Based Planning Algorithms for Multi-Objective Missions by Md Mahbubur Rahman
Sampling-Based Planning Algorithms for Multi-Objective MissionsSampling-Based Planning Algorithms for Multi-Objective Missions
Sampling-Based Planning Algorithms for Multi-Objective Missions
An Exact Solution To Support Vector Mixture by Karin Faust
An Exact Solution To Support Vector MixtureAn Exact Solution To Support Vector Mixture
An Exact Solution To Support Vector Mixture
Karin Faust2 views
Exploiting Hierarchy in the Abstraction-Based Verification of Statecharts Usi... by Akos Hajdu
Exploiting Hierarchy in the Abstraction-Based Verification of Statecharts Usi...Exploiting Hierarchy in the Abstraction-Based Verification of Statecharts Usi...
Exploiting Hierarchy in the Abstraction-Based Verification of Statecharts Usi...
Akos Hajdu157 views
My Postdoctoral Research by Po-Ting Wu
My Postdoctoral ResearchMy Postdoctoral Research
My Postdoctoral Research
Po-Ting Wu231 views
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li... by IFPRI-EPTD
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
Biosight: Quantitative Methods for Policy Analysis - Introduction to GAMS, Li...
IFPRI-EPTD641 views
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests? by Agile Lietuva
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
Agile Lietuva632 views

More from Filip Van Laenen

Drawing for IT Architects by
Drawing for IT ArchitectsDrawing for IT Architects
Drawing for IT ArchitectsFilip Van Laenen
264 views156 slides
How JSR 385 could have saved the Mars Climate Orbiter by
How JSR 385 could have saved the Mars Climate OrbiterHow JSR 385 could have saved the Mars Climate Orbiter
How JSR 385 could have saved the Mars Climate OrbiterFilip Van Laenen
496 views65 slides
How JSR-385 Could Have Saved the Mars Climate Orbiter by
How JSR-385 Could Have Saved the Mars Climate OrbiterHow JSR-385 Could Have Saved the Mars Climate Orbiter
How JSR-385 Could Have Saved the Mars Climate OrbiterFilip Van Laenen
369 views56 slides
Clouds with Trenches and Sharp Edges by
Clouds with Trenches and Sharp EdgesClouds with Trenches and Sharp Edges
Clouds with Trenches and Sharp EdgesFilip Van Laenen
263 views46 slides
Become an SVG Architect, not a PowerPoint Architect by
Become an SVG Architect, not a PowerPoint ArchitectBecome an SVG Architect, not a PowerPoint Architect
Become an SVG Architect, not a PowerPoint ArchitectFilip Van Laenen
251 views15 slides
Dial M for Mutation by
Dial M for MutationDial M for Mutation
Dial M for MutationFilip Van Laenen
225 views99 slides

More from Filip Van Laenen(17)

How JSR 385 could have saved the Mars Climate Orbiter by Filip Van Laenen
How JSR 385 could have saved the Mars Climate OrbiterHow JSR 385 could have saved the Mars Climate Orbiter
How JSR 385 could have saved the Mars Climate Orbiter
Filip Van Laenen496 views
How JSR-385 Could Have Saved the Mars Climate Orbiter by Filip Van Laenen
How JSR-385 Could Have Saved the Mars Climate OrbiterHow JSR-385 Could Have Saved the Mars Climate Orbiter
How JSR-385 Could Have Saved the Mars Climate Orbiter
Filip Van Laenen369 views
Clouds with Trenches and Sharp Edges by Filip Van Laenen
Clouds with Trenches and Sharp EdgesClouds with Trenches and Sharp Edges
Clouds with Trenches and Sharp Edges
Filip Van Laenen263 views
Become an SVG Architect, not a PowerPoint Architect by Filip Van Laenen
Become an SVG Architect, not a PowerPoint ArchitectBecome an SVG Architect, not a PowerPoint Architect
Become an SVG Architect, not a PowerPoint Architect
Filip Van Laenen251 views
Mutasjonstesting – Lag bugs for å få bedre kode by Filip Van Laenen
Mutasjonstesting – Lag bugs for å få bedre kodeMutasjonstesting – Lag bugs for å få bedre kode
Mutasjonstesting – Lag bugs for å få bedre kode
Filip Van Laenen445 views
Hvem kommer til å vinne kommunevalget? by Filip Van Laenen
Hvem kommer til å vinne kommunevalget?Hvem kommer til å vinne kommunevalget?
Hvem kommer til å vinne kommunevalget?
Filip Van Laenen600 views
How Free Data Can Drive Some of the Monkey Business Out of Political Journali... by Filip Van Laenen
How Free Data Can Drive Some of the Monkey Business Out of Political Journali...How Free Data Can Drive Some of the Monkey Business Out of Political Journali...
How Free Data Can Drive Some of the Monkey Business Out of Political Journali...
Filip Van Laenen586 views

Recently uploaded

Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
25 views26 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
16 views3 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
21 views15 slides
Evolving the Network Automation Journey from Python to Platforms by
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 views21 slides
6g - REPORT.pdf by
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdfLiveplex
10 views23 slides

Recently uploaded(20)

Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely25 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab21 views
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman36 views
Powerful Google developer tools for immediate impact! (2023-24) by wesley chun
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)
wesley chun10 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc11 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays17 views

Mutation testing (OOP 2012, 2012-JAN-24)

  • 1. Mutation Testing Filip van Laenen OOP 2012 2012-01-24 © Computas AS 27.01.12
  • 2. Agenda • Basics of mutation testing • Relation to other testing techniques • Example • Mutation testing techniques • Mutation testing tools • Personal experiences and recommendations • Improvements • Questions and comments 2 © Computas AS 27.01.12
  • 3. Basics of Mutation Testing 3 © Computas AS 27.01.12
  • 4. Mutation Testing in a Nutshell Seeking The Summoner @ The Daily WTF http://thedailywtf.com/Articles/Seeking-The-Summoner.aspx 4 © Computas AS 27.01.12
  • 5. Mutation Testing in a Nutshell (cont'd) 5 © Computas AS 27.01.12
  • 6. Mutation Testing in a Nutshell (cont'd) 6 © Computas AS 27.01.12
  • 7. Mutation Testing in a Nutshell (cont'd) • Unit tests guard the source code • But who guards the guardians? • Do the unit tests cover all source code? • Lines? • Branches? • Paths? • Do the unit tests test the right things? Mutation testing tests the tests! 7 © Computas AS 27.01.12
  • 8. Mutation Testing in a Nutshell (cont'd) 8 © Computas AS 27.01.12
  • 9. Mutation Testing in a Nutshell (cont'd) 9 © Computas AS 27.01.12
  • 10. Mutation Testing in a Nutshell (cont'd) 10 © Computas AS 27.01.12
  • 11. Mutation Testing in a Nutshell (cont'd) 11 © Computas AS 27.01.12
  • 12. Mutation Testing in a Nutshell (cont'd) 12 © Computas AS 27.01.12
  • 13. Mutation Testing in a Nutshell (cont'd) 13 © Computas AS 27.01.12
  • 14. Mutation Testing in a Nutshell (cont'd) def max(a, b) { return (a < b) ? b : a; } def max(a, b) { return (a ≤ b) ? b : a; } 14 © Computas AS 27.01.12
  • 15. Mutation Testing in a Nutshell (cont'd) 15 © Computas AS 27.01.12
  • 16. Does Mutation Testing Work? “ In practice, if the software contains a fault, there will usually be a set of mutants that can only be killed by a test case that also detects that fault. Geist et. al., “Estimation and Enhancement of Real-time Software Reliability through Mutation Analysis,” 1992 16 © Computas AS 27.01.12
  • 17. Does Mutation Testing Work? (cont'd) “ Complex faults are coupled to simple faults in such a way that a test data set that detects all simple faults in a program will detect most complex faults. K. Wah, “Fault Coupling in Finite Bijective Functions,” 1995 17 © Computas AS 27.01.12
  • 18. Does Mutation Testing Work? (cont'd) • “Generated mutants are similar to real faults.” • Andrews, Briand, Labiche, ICSE 2005 • “Mutation testing is more powerful than statement or branch coverage.” • Walsh, Ph.D. Thesis, State University of New York at Binghampton, 1985 • “Mutation testing is superior to data flow coverage criteria.” • Frankl, Weiss, Hu, Journal of Systems and Software, 1997 18 © Computas AS 27.01.12
  • 19. Relation to Other Testing Techniques 19 © Computas AS 27.01.12
  • 20. Relation to Other Testing Techniques • Unit tests • Test-Driven Development (TDD) • Test coverage • Static code analysis • Fuzz testing 20 © Computas AS 27.01.12
  • 21. Relation to Other Testing Techniques 21 © Computas AS 27.01.12
  • 22. Is Mutation Testing New? • R. Lipton, “Fault Diagnosis of Computer Programs,” 1971 • R. Lipton et. al., “Hints on Test Data Selection: Help for the Practicing Programmer,” 1978 • Historical obstacles: • No unit testing • No TDD • Time-consuming • No integration with IDEs 22 © Computas AS 27.01.12
  • 23. Practical Example of Mutation Testing 23 © Computas AS 27.01.12
  • 24. Practical Example # Returns the maximum of a. # @param a An array of integers. def max(a) { return …; } 24 © Computas AS 27.01.12
  • 25. Practical Example (cont'd) Omitted: max(null) Omitted: max([]) def max(a) { return …; } 25 © Computas AS 27.01.12
  • 26. Practical Example (cont'd) Assertion: max([0]) = 0 def max(a) { return 0; } 26 © Computas AS 27.01.12
  • 27. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 def max(a) { return 0; } 27 © Computas AS 27.01.12
  • 28. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 def max(a) { return a.first; } 28 © Computas AS 27.01.12
  • 29. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { return a.first; } 29 © Computas AS 27.01.12
  • 30. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { nit t ests! m ← a.first; U age! cover foreach (e ∈ a) line 100% age? if (e > m) over nch c m ← e; 100% b ra return m; } 30 © Computas AS 27.01.12
  • 31. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { m ← a.first; foreach (e ∈ a) if (e > m) m ← e; return m; } 31 © Computas AS 27.01.12
  • 32. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { m ← a.first; foreach (e ∈ a) if (true) m ← e; return m; } 32 © Computas AS 27.01.12
  • 33. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { return a.last; } 33 © Computas AS 27.01.12
  • 34. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 Assertion: max([2, 1]) = 2 def max(a) { return a.last; } 34 © Computas AS 27.01.12
  • 35. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 Assertion: max([2, 1]) = 2 def max(a) { m ← a.first; foreach (e ∈ a) if (e > m) m ← e; return m; } 35 © Computas AS 27.01.12
  • 36. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 Assertion: max([2, 1]) = 2 def max(a) { m ← -∞; foreach (e ∈ a) if (e > m) m ← e; return m; } 36 © Computas AS 27.01.12
  • 37. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { m ← a.first; foreach (e ∈ a) if (e > m) ← Implicit else-branch! m ← e; return m; } 37 © Computas AS 27.01.12
  • 38. Practical Example (cont'd) Assertion: max([0]) = 0 Assertion: max([1]) = 1 Assertion: max([1, 2]) = 2 def max(a) { m ← -∞; foreach (e ∈ a) ? rage if (e > m) h cove ← Implicitcelse-branch! ran m ← e; 10 0% b return m; } 38 © Computas AS 27.01.12
  • 39. Practical Example (cont'd) • 100% test coverage may be illusory • Line coverage • Branch coverage • Path coverage • TDD principles easily broken • Even if you're very careful 39 © Computas AS 27.01.12
  • 40. Mutation Testing Techniques 40 © Computas AS 27.01.12
  • 41. Mutation Testing Techniques • Three aspects: • Mutation injection • Mutation types • Unit test selection per mutant • Key properties: • Efficiency • Performance 41 © Computas AS 27.01.12
  • 42. Mutation Injection • Source code mutation • Binary code mutation • Caveats: • De-mutation • Compilation errors • Invalid binary code 42 © Computas AS 27.01.12
  • 43. Mutation Types • Some mutations never change behaviour • Constants reused by unit tests • Log messages • Some mutations can change behaviour • Switching between < and ≠ • Switching between < and ≤ • Some mutations always change behaviour • Switching between < and ≥ 43 © Computas AS 27.01.12
  • 44. Mutation Types (cont'd) def max(a, b) { return (a < b) ? b : a; } def max(a, b) { return (a ≤ b) ? b : a; } def max(a, b) { return (a ≥ b) ? b : a; } 44 © Computas AS 27.01.12
  • 45. Mutation Types (cont'd) for (i ← 0; i < 10; i++) … for (i ← 0; i ≠ 10; i++) … for (i ← 0; i ≥ 10; i++) … 45 © Computas AS 27.01.12
  • 46. Mutation Types Guaranteed to Change Behaviour * • Negation of the comparison • Switching between = and ≠ • Switching between < and ≥ • Switching between > and ≤ • Negation of boolean conditions • Adding a ¬, ! or ~ • Shortcutting boolean conditions • Replacement with True or False 46 © Computas AS 27.01.12
  • 47. Unit Test Selection • Goal: find the unit test that “kills” the mutant • Selection aids: • Hints • Name/package matching • Code coverage tools • Automatic learning • Other heuristics 47 © Computas AS 27.01.12
  • 48. Unit Test Selection (cont'd) • System: • 50 classes • 20 unit tests per class • 1 ms per unit test • Unit testing time: 50 × 20 × 1ms = 1s • 10 mutants per class: • Brute-force: 10 × 50 × 1s = 6m 20s • Educated: 10 × 50 × 20 × 1ms = 10s 48 © Computas AS 27.01.12
  • 49. Unit Test Selection (cont'd) • System: • 500 classes • 20 unit tests per class • 1 ms per unit test • Unit testing time: 500 × 20 × 1ms = 10s • 10 mutants per class: • Brute-force: 10 × 500 × 10s = 13h 53m 20s • Educated: 10 × 500 × 20 × 1ms = 1m 40s 49 © Computas AS 27.01.12
  • 50. Complexity • f: Number of function points • φ: Number of function points per class, ≥ 1 • τ: Number of unit tests per function point, ≥ 1 • μ: Number of mutants per function point, ≥ 1 • Brute-force: (f × τ) × (f × μ) = τ × μ × f² • Educated force: τ × μ × φ × f • Ideal: τ × μ × f 50 © Computas AS 27.01.12
  • 51. Complexity (cont'd) • c: Number of classes • φ: Number of function points per class, ≥ 1 • τ: Number of unit tests per function point, ≥ 1 • μ: Number of mutants per function point, ≥ 1 • Brute-force: (f × τ) × (f × μ) = τ × μ × φ² × c² • Educated force: τ × μ × φ² × c • Ideal: τ × μ × φ × c 51 © Computas AS 27.01.12
  • 52. Loops for (i ← 0; i < 10; i++) … for (i ← 0; i < 10; i--) … 52 © Computas AS 27.01.12
  • 53. Infinite Loops • Terminate mutants that take too long to run • What's too long? • Ruins the performance • Can be hard to predict 53 © Computas AS 27.01.12
  • 54. Other Problems • Recursion: • Stack overflows • Out of memory exceptions • Syntax errors • Segmentation faults 54 © Computas AS 27.01.12
  • 55. Mutation Testing Tools 55 © Computas AS 27.01.12
  • 56. Mutation Testing Tools • Ruby: Heckle • Java: • Jester • Jumble • PIT • C#: Nester • Python: Pester 56 © Computas AS 27.01.12
  • 57. Heckle • Ruby • Test::Unit and rSpec • Usually run from the command-line • Runs a set of unit tests on a class or a method • Good to-the-point reporting • Good performance • Virtually no documentation • http://rubyforge.org/projects/seattlerb/ • http://docs.seattlerb.org/heckle/ 57 © Computas AS 27.01.12
  • 58. Heckle Mutations • Booleans • Numbers • Strings • Symbols • Ranges • Regexes • Branches (if, while, unless, until) 58 © Computas AS 27.01.12
  • 59. Heckle Sample Output Initial tests pass. Let's rumble. ***************************************************************** *** Greeter#greet loaded with 3 possible mutations ***************************************************************** 3 mutations remaining... 2 mutations remaining... 1 mutations remaining... No mutants survived. Cool! 59 © Computas AS 27.01.12
  • 60. My Heckle Sample Output filip@filip-laptop:~/github/wruf$ rake heckle (in /home/filip/github/wruf) Doing mutation testing on 15 method(s) of FlickrSearcher against test/flickr_searcher_unit_test.rb: o FlickrSearcher#convert_photo_info [1/15] o FlickrSearcher#create_form_data_to_get_info_about_photo [2/15] o FlickrSearcher#create_form_data_to_get_info_about_user [3/15] o FlickrSearcher#create_form_data_to_search_photos [4/15] o FlickrSearcher#do_rest_request [5/15] o FlickrSearcher#get_author [6/15] … o FlickrSearcher#get_photo_info [12/15] o FlickrSearcher#get_photo_url [13/15] o FlickrSearcher#get_ref_url [14/15] o FlickrSearcher#get_ref_url_from_xml_photo_info [15/15] Checked 192 mutations, and no issues were found in FlickrSearcher. 60 © Computas AS 27.01.12
  • 61. My Heckle Sample Output (cont'd) Doing mutation testing on 7 method(s) of WrufSettings against test/wruf_settings_unit_test.rb: o WrufSettings#dimensions [1/7] o WrufSettings#dimensions= [2/7] o WrufSettings#hours [3/7] o WrufSettings#hours= [4/7] o WrufSettings#tags [5/7] o WrufSettings#tolerance [6/7] o WrufSettings#tolerance= [7/7] Checked 0 mutations, and no issues were found in WrufSettings. 61 © Computas AS 27.01.12
  • 62. Heckle Sample Report --- original +++ mutation def calculate_precision(rescaled_number) if (rescaled_number < 9.995) then return 2 else if (rescaled_number < 99.95) then return 1 else if (rescaled_number >= 99.95) then return 0 else - return -1 + return -70 end end end end 62 © Computas AS 27.01.12
  • 63. Jester • Java • JUnit • Usually run from the command-line • Grester for Maven2 • Operates on source code • Runs all unit tests on all classes • Reporting and documentation could be better • http://jester.sourceforge.net/ • http://sourceforge.net/projects/grester/ 63 © Computas AS 27.01.12
  • 64. Jester Sample Report Overview 64 © Computas AS 27.01.12
  • 65. Jester Sample Detailed Report 65 © Computas AS 27.01.12
  • 66. Pester and Nester • Pester • Jester for Python • PyUnit • Nester • Port of Jester for C# • NUnit • Integrated with Visual Studio • But outdated… • http://nester.sourceforge.net/ 66 © Computas AS 27.01.12
  • 67. Nester Sample Report 67 © Computas AS 27.01.12
  • 68. Jumble • Java • JUnit • Run from the command-line • Operates on byte code • Runs unit tests on a class • Reporting and documentation could be better • Claims to be faster than Jester • http://jumble.sourceforge.net/index.html 68 © Computas AS 27.01.12
  • 69. Jumble Sample Report Mutating Foo Tests: FooTest Mutation points = 12, unit test time limit 2.02s .. M FAIL: Foo:31: negated conditional M FAIL: Foo:33: negated conditional M FAIL: Foo:34: - -> + M FAIL: Foo:35: negated conditional ...... Score: 67% 69 © Computas AS 27.01.12
  • 70. PIT • Java • JUnit • Maven or command-line • Operates on byte code • Large set of mutators • Also possibly equivalent mutators available • Highly configurable • Sensible defaults • http://pitest.org/ 70 © Computas AS 27.01.12
  • 71. PIT Mutators • Conditionals Boundary • Negate Conditionals • Math • Increments • Invert Negatives • Inline Constant* • Return Values • Void Method Call • Non Void Method Call* • Constructor Call* 71 © Computas AS 27.01.12
  • 72. PIT Sample Report 72 © Computas AS 27.01.12
  • 73. Personal Experiences and Recommendations 73 © Computas AS 27.01.12
  • 74. Experiences and Recommendations • Use mutation testing from day 1 • Start on a small code base • Keep number of unit tests per class low • Have small classes • Select a good tool • Configurable • Flexible • One that can output the mutant 74 © Computas AS 27.01.12
  • 75. Experiences and Recommendations (cont'd) • Believe the tool • Or try to proof that the tool is wrong • Fix the problem • Don't turn mutation testing off • Embrace the “more than 100%” test coverage • Path coverage • Less code • More unit tests • More intelligent unit tests 75 © Computas AS 27.01.12
  • 76. Improvements 76 © Computas AS 27.01.12
  • 77. Improvements • Integration with more unit testing frameworks • Better unit test–source code mapping • Better heuristics • Parallellisation • Better reporting • IDE integration • Building tool integration 77 © Computas AS 27.01.12
  • 78. The Ideal Mutation Testing Tool™ • Easy integration with building tools • Easy integration with IDEs • Support for all unit testing frameworks • Human-aided unit test selection heuristics • Full parallellisation • Good source code mutation reporting 78 © Computas AS 27.01.12
  • 79. Questions? Contact: fvl@computas.com @filipvanlaenen Computas AS Tel +47-67 83 10 00 Lysaker Torg 45, pb 482 Fax +47-67 83 10 01 N-1327 Lysaker Org.nr: NO 986 352 325 MVA NORWAY www.computas.com 79 © Computas AS 27.01.12