Transcript
Page 1: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Mutation testingHow good your tests really are?

Marcin Zajączkowski

Brno, 2014-02-08

Page 2: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

About me

Java architect TDD practitioner

Team mentor Clean code developer

Software CraftsmanshipEvangelist

Fedora packager FOSS developer Linux enthusiast

IT Trainer Code quality freak Blogger

Page 3: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Presentation plan

● What is and how works mutation testing?● Why is almost not known and rarery used?● PIT – tool which works● Mutants in action – live coding● Benefits of using● Adaptation in real life project

Page 4: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.erniemort.com/

Page 5: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.townofdarienny.com/

Page 6: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.censusfinder.com/nebraska-historical-museums.htm

Page 7: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://muratordom.pl/

Page 8: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.oldwestlawmansforgottenmemoir.com/memoir_bringsV13.html

Page 9: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

https://weshouldnamethissoon.wordpress.com/

Page 10: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.rustyaccents.com/

Page 11: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://www.nps.gov/fosm/historyculture/executions-at-fort-smith-1873-to-1896.htm

Page 12: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

https://secure.flickr.com/photos/kingdafy/500117608/

Page 13: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Sfingowane przestępstwo

https://secure.flickr.com/photos/7402220@N02/491093210/

Page 14: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

2 - http://goo.gl/C8yFe

Page 15: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

http://publish.illinois.edu/libraryitnews/2012/06/

Page 16: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Analogies

Project

Bugs in code

Automated tests

Code coverage

Mutants in code

Town

Crimes

Sheriffs

Patrol paths

Provocations

The idea with an analogy to criminality and law enforcement taken from Chris Rimmer

Page 17: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Mutation testingWhat's it about?

● Intentionally break selected line of production code (introduce a mutation)

● Check if any test detects a modification (if it fails)

● Survived mutation (which were not detected) are a potential bugs which would not be detected by automated tests

Page 18: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Common issues

● Small number of tools for Java (many not maintained anymore)

● Long execution time● Required production code

modification● Infinite loops● Stack overflow

http://bestclipartblog.com/27-tools-clip-art.html/tools-clip-art-2

Page 19: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

PIT – mutations fast

● Bytecode manipulation● Mutation of the lines with standard coverage

only● Execution of related test only● Parallel execution● Incremental analysis

http://carhumor.net/blast-from-the-past/

Page 20: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

PIT – various mutations

● Conditionals Boundary Mutator● Negate Conditionals Mutator● Math Mutator● Increments Mutator● Invert Negatives Mutator● Return Values Mutator● (Non) Void Method Calls Mutator● And more...

1 - http://blog.spoongraphics.co.uk/tutorials/create-a-cute-furry-vector-monster-in-illustrator 2 - http://blog.spoongraphics.co.uk/tutorials/create-a-cute-vector-monster-from-a-pencil-sketch

Page 21: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

PIT – rich ecosystem

TestNG

SpockLogos – home pages of mentioned projects

Page 22: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

PIT – pros

● Fast● Powerful● Widely supported

Page 23: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Some Java alternatives

● Javalanche – small ecosystem, last commit in 2012

● µJava – limited access to source code● Jester – no longer maintained● Jumple – no longer maintained● Judy – no longer maintained

Page 24: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Other languagesSelected tools

● MutPy – Python – actively developed● Mutagenesis – PHP – actively developed

(judgedim fork)● Mutant – Ruby – actively developed● NinjaTurtles - .NET – last commit in 2012

Page 25: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Mutants in action

http://www.adolescentadulthood.com/2013/01/23/how-did-the-teenage-mutant-ninja-turtles-get-their-names/

Page 26: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

What can you get?

● Better code quality● Less bugs in production● Job satisfaction● ... (other benefits from writing testable code)

● Information how good your tests really are● Places in code that are not properly tested

– Better than with „normal” code coverage

Page 27: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

When to use?

● Greenfield project developed with high quality in mind

● High coverage, but still bugs in production which could (and should) be detected by tests

● Doubts about test suite quality– HLD requirement – 95% minimal code

coverage level with the development team with no experience in automated testing

● Improve legacy system with low code quality and/or without tests

Page 28: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Prepare your project

● Write automatic tests● Write fast automatic unit tests (not only slow

integration ones)● Separate fast unit tests from slow integration

tests– Be able to run only selected group of tests

Page 29: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Does anyone use itin the real life project?

● Yes :-)

● British Sky

Broadcasting● TheLadders● Jumi● Maybe you?

http://www.mysciencework.com/fr/MyScienceNews/10027/de-l-in-opportunite-des-open-spaces-dans-les-labos

Page 30: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Summary of benefits

Verification of effectiveness of automatic test

More reliable code

Less troubles at work

More time for interesting things

Increased job satisfaction

This presentation is available under the terms of Creative Commons Attribution-NonCommercial-ShareAlike 3.0(with exclusion of the parts created by other people – including photos). Version 1.0.5-dc.

Page 31: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Questions?

Online feedback: http://devconf.cz/f/86

Page 32: Mutation testing - How good your tests really are? testing How good your tests really are? Marcin ... Team mentor Clean code developer Software Craftsmanship ... What is and how works

Thank you for your attention

Marcin Zają[email protected]

http://blog.solidsoft.info/

@SolidSoftBlog


Top Related