Mutation Testing in Patterns Documentation

Similar documents
Celery-RabbitMQ Documentation

bottle-rest Release 0.5.0

alphafilter Documentation

Scrapy-Redis Documentation

White Box Testing III

Plumeria Documentation

pytest-benchmark Release 2.5.0

Bitdock. Release 0.1.0

python-quirc Documentation

prompt Documentation Release Stefan Fischer

SnowAlert Documentation. Snowflake Security

diceware Documentation

Python Schema Generator Documentation

Poetaster. Release 0.1.1

chatterbot-weather Documentation

turbo-hipster Documentation

ValuePRO Tutorial Internet Explorer 8 Configuration

Assignment 2. CS 234 Fall 2018 Sandy Graham. Create()

ACT-R RPC Interface Documentation. Working Draft Dan Bothell

Silpa Documentation. Release 0.1. Santhosh Thottingal

Python Finite State Machine. Release 0.1.5

Django-CSP Documentation

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

pynetworktables2js Documentation

django-reinhardt Documentation

doubles Documentation

django-dynamic-db-router Documentation

picrawler Documentation

Risks of Computers. Steven M. Bellovin April 8,

BanzaiDB Documentation

neo4django Documentation

cwmon-mysql Release 0.5.0

django-auditlog Documentation

Pymixup Documentation

Python Project Example Documentation

Lecture Conservative Garbage Collection. 3.2 Precise Garbage Collectors. 3.3 Other Garbage Collection Techniques

PyCRC Documentation. Release 1.0

obfuscator Documentation

gpib-ctypes Documentation

PyZabbixObj Documentation

os-testr Documentation

Rubix Documentation. Release Qubole

sainsmart Documentation

TangeloHub Documentation

Impedance Analyzer Documentation

TPS Documentation. Release Thomas Roten

Django Groups Manager Documentation

python-samplerate Documentation

lazy-object-proxy Release 1.3.1

L.I.S.A Linux Client Documentation

bootmachine Documentation

Simple libtorrent streaming module Documentation

pysharedutils Documentation

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

Python AutoTask Web Services Documentation

Tuesday, November 15. Testing

Developing large-scale Applications in Python

Risks of Computers. Steven M. Bellovin April 6,

zope.location Documentation

Roman Numeral Converter Documentation

GoCD Python API client Documentation

Python State Machine Documentation

collective.table Documentation Release 1.0.1

google-search Documentation

Kiki Documentation. Release 0.7a1. Stephen Burrows

What is an algorithm?

python-docker-machine Documentation

Ceilometer Documentation

Map-Reduce. Marco Mura 2010 March, 31th

Ontology mutation testing

MicroPython Development Documentation Documentation

retask Documentation Release 1.0 Kushal Das

youckan Documentation

Test-Driven Development (TDD)

flask-dynamo Documentation

Python Release September 11, 2014

Randomized Algorithms: Element Distinctness

helper Documentation Release Gavin M. Roy

I hate money. Release 1.0

Django-frontend-notification Documentation

PrettyPandas Documentation

pydrill Documentation

AXIOMS FOR THE INTEGERS

Quicksort. Alternative Strategies for Dividing Lists. Fundamentals of Computer Science I (CS F)

Python wrapper for Viscosity.app Documentation

RandoPony Documentation

AnyDo API Python Documentation

CS Lecture 18: Card Tricks. Announcements. Slides by D. Gries, L. Lee, S. Marschner, W. White

Ensure Documentation. Release Andrey Kislyuk

Django Groups Manager Documentation

Archan. Release 2.0.1

xmljson Documentation

Google Domain Shared Contacts Client Documentation

nptdms Documentation Release Adam Reeve

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

I2C LCD Documentation

django-redis-cache Documentation

Testing. UW CSE 160 Winter 2016

DNS Zone Test Documentation

GridMap Documentation

Transcription:

Mutation Testing in Patterns Documentation Release 1.0 Alexander Todorov Aug 18, 2016

Contents 1 Make sure your tools work 3 2 Make sure your tests work 5 3 Divide and conquer 7 4 Fail fast 9 5 Python: Refactor if string!= 11 6 Appendix. Mutation testing with Python 13 7 Indices and tables 15 i

ii

Mutation Testing in Patterns Documentation, Release 1.0 Mutation testing is a technique used to evaluate the quality of existing software tests. Mutation testing involves modifying a program in small ways, for example replacing True constants with False and re-running its test suite. When the test suite fails the mutant is killed. This tells us how good the test suite is. The goal of this paper is to describe different software and testing patterns related using practical examples. Some of them are language specific so please see the relevant sections for information about installing and running the necessary tools and examples. Contents 1

Mutation Testing in Patterns Documentation, Release 1.0 2 Contents

CHAPTER 1 Make sure your tools work Mutation testing relies on dynamically modifying program modules and loading the mutated instance from memory. Depending on the language specifics there may be several ways to refer to the same module. In Python the following are equivalent import sandwich.ham.ham obj = sandwich.ham.ham.someclass() from sandwich.ham import ham obj = ham.someclass() Note: The equivalency here is in terms of having access to the same module API. When we mutation test the right-most ham module our tools may not be able to resolve to the same module if various importing styles are used. For example see python/example_00/readme. Another possible issue is with programs that load modules dynamically or change the module search path at runtime. Depending on how the mutation testing tool works these operations may interfere with it. For example see python/example_01/readme. TL,DR: explore your test tool first and manually verify the results before going further. Unless you know the tools don t trust them! 3

Mutation Testing in Patterns Documentation, Release 1.0 4 Chapter 1. Make sure your tools work

CHAPTER 2 Make sure your tests work Mutation testing relies on the fact that your test suite will fail when a mutation is introduced. In turn any kind of failure will kill the mutant! The mutation test tool has no way of knowing whether your test suite failed because the mutant tripped one of the assertions or whether it failed due to other reasons. For example see python/example_02/readme TL,DR: make sure your test suite is robust and doesn t randomly fail due to external factors! 5

Mutation Testing in Patterns Documentation, Release 1.0 6 Chapter 2. Make sure your tests work

CHAPTER 3 Divide and conquer The basic mutation test algorithm is this for operator in mutation-operators: for site in operator.sites(code): operator.mutate(site) run_tests() mutation-operators are the things that make small changes to your code operator.sites are the places in your code where this operator can be applied As you can see mutation testing is a very expensive operation. For example the pykickstart project started with 5523 possible mutations and 347 tests, which took on average 100 seconds to execute. A full mutation testing execution needs more than 6 days to complete! In practice however not all tests are related to, or even make use of all program modules. This means that mutated operators are only tested via subset of the entire test suite. This fact can be used to reduce execution time by scheduling mutation tests against each individual file/module using only the tests which are related to it. The best case scenario is when your source file names map directly to test file names. For example something like this for f in `find./src -type f -name "*.py" sort`; do TEST_NAME="tests/$f" runtests $f $TEST_NAME done Where runtests executes the mutation testing tool against a single file and executes only the test which is related to this file. For pykickstart this approach reduced the entire execution time to little over 6 hours! TL,DR: Good source code and test organization will allow easy division of test runs and tremendously speed up your mutation testing execution time! 7

Mutation Testing in Patterns Documentation, Release 1.0 8 Chapter 3. Divide and conquer

CHAPTER 4 Fail fast Mutation testing relies on your test suite failing when it detects a faulty mutation. It doesn t matter which particular test has failed because most of the tools have no way of telling whether or not the failed test is related to the mutated code. That means it also doesn t matter if there are more than one failing tests so you can use this to your advantage. TL,DR: Whenever your test tools and framework support the fail fast option make use of it to reduce test execution time even more! 9

Mutation Testing in Patterns Documentation, Release 1.0 10 Chapter 4. Fail fast

CHAPTER 5 Python: Refactor if string!= Comparison operators may be mutated with each other which gives, depending on the langauge about 10 possible mutations. Every time str is not an empty string the following 3 variants are evaluated to True: if str!= "" if str > "" if str not in "" The existing test cases pass and these mutations are never killed. Refactoring this to if str: do_something() is the best way to go about it. This also reduces the total number of possible mutations. For example see python/example_03/readme TL,DR: Refactor if str!= "": to if str:! 11

Mutation Testing in Patterns Documentation, Release 1.0 12 Chapter 5. Python: Refactor if string!=

CHAPTER 6 Appendix. Mutation testing with Python Cosmic-Ray is the mutation testing tool for Python. It is recommended that you install the latest version from git: pip install https://github.com/sixty-north/cosmic-ray/zipball/master Cosmic-Ray uses Celery to allow concurrent execution of workers (e.g. mutation test jobs). To start the worker cd myproject/ celery -A cosmic_ray.tasks.worker worker To execute a test job (called session) use a different terminal and cd myproject/ cosmic-ray run --baseline=10 session_name.json some/module.py -- tests/some/test.py Note: Test runner and additional test parameters can be specified. Refer to Cosmic-Ray s documentation for more details! To view the mutation results execute cosmic-ray report session_name.json 13

Mutation Testing in Patterns Documentation, Release 1.0 14 Chapter 6. Appendix. Mutation testing with Python

CHAPTER 7 Indices and tables genindex modindex search 15