All Projects → boxed → Mutmut

boxed / Mutmut

Licence: bsd-3-clause
Mutation testing system

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Mutmut

Gradle Pitest Plugin
Gradle plugin for PIT Mutation Testing
Stars: ✭ 144 (-69.56%)
Mutual labels:  mutation-testing
dextool
Suite of C/C++ tooling built on LLVM/Clang
Stars: ✭ 81 (-82.88%)
Mutual labels:  mutation-testing
mutant-swarm
Mutation testing framework and code coverage for Hive SQL
Stars: ✭ 20 (-95.77%)
Mutual labels:  mutation-testing
Awesome Mutation Testing
Mutation testing resources: how to make better code by introducing bugs
Stars: ✭ 207 (-56.24%)
Mutual labels:  mutation-testing
dumbmutate
Simple mutation-testing
Stars: ✭ 32 (-93.23%)
Mutual labels:  mutation-testing
pitest-descartes
Descartes supports developers to improve their test suites by reporting weak spots in covered code
Stars: ✭ 113 (-76.11%)
Mutual labels:  mutation-testing
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+2854.76%)
Mutual labels:  mutation-testing
Mutagen
Breaking your Rust code for fun and profit
Stars: ✭ 410 (-13.32%)
Mutual labels:  mutation-testing
universalmutator
Regexp based tool for mutating generic source code across numerous languages
Stars: ✭ 105 (-77.8%)
Mutual labels:  mutation-testing
vertigo
Mutation Testing for Ethereum Smart Contracts
Stars: ✭ 100 (-78.86%)
Mutual labels:  mutation-testing
Mutpy
MutPy is a mutation testing tool for Python 3.x source code
Stars: ✭ 248 (-47.57%)
Mutual labels:  mutation-testing
Faultify
Byte Code Dotnet Mutation Utility
Stars: ✭ 16 (-96.62%)
Mutual labels:  mutation-testing
mutatest
Python mutation testing: test your tests! Safely run mutation trials without source code modifications and see what will get past your test suite.
Stars: ✭ 50 (-89.43%)
Mutual labels:  mutation-testing
Stryker Js
Mutation testing for JavaScript and friends
Stars: ✭ 2,043 (+331.92%)
Mutual labels:  mutation-testing
mutant
mutation testing for R
Stars: ✭ 13 (-97.25%)
Mutual labels:  mutation-testing
Mutant
Automated code reviews via mutation testing - semantic code coverage.
Stars: ✭ 1,794 (+279.28%)
Mutual labels:  mutation-testing
mutode
Mutation testing for JavaScript and Node.js
Stars: ✭ 61 (-87.1%)
Mutual labels:  mutation-testing
Cosmic Ray
Mutation testing for Python
Stars: ✭ 470 (-0.63%)
Mutual labels:  mutation-testing
Muter
🔎 Automated mutation testing for Swift 🕳️
Stars: ✭ 293 (-38.05%)
Mutual labels:  mutation-testing
pitmp-maven-plugin
Maven plugin to handle multi module projects for PiTest
Stars: ✭ 36 (-92.39%)
Mutual labels:  mutation-testing

mutmut - python mutation tester

.. image:: https://travis-ci.org/boxed/mutmut.svg?branch=master :target: https://travis-ci.org/boxed/mutmut

.. image:: https://readthedocs.org/projects/mutmut/badge/?version=latest :target: https://mutmut.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

.. image:: https://codecov.io/gh/boxed/mutmut/branch/master/graph/badge.svg :target: https://codecov.io/gh/boxed/mutmut

.. image:: https://img.shields.io/discord/767914934016802818.svg :target: https://discord.gg/cwb9uNt

Mutmut is a mutation testing system for Python, with a strong focus on ease of use. If you don't know what mutation testing is try starting with this article <https://hackernoon.com/mutmut-a-python-mutation-testing-system-9b9639356c78>_.

Some highlight features:

  • Found mutants can be applied on disk with a simple command making it very easy to work with the results
  • Remembers work that has been done, so you can work incrementally
  • Supports all test runners (because mutmut only needs an exit code from the test command)
  • If you use the hammett <https://github.com/boxed/hammett> test runner you can go extremely fast! There's special handling for this runner that has some pretty dramatic results.
  • Can use coverage data to only do mutation testing on covered lines
  • Battle tested on real libraries by multiple companies

If you need to run mutmut on a python 2 code base use mutmut 1.5.0. Mutmut 1.9.0 is the last version to support python 3.4, 3.5 and 3.6.

Install and run

You can get started with a simple:

.. code-block:: console

pip install mutmut
mutmut run

This will by default run pytest (or unittest if pytest is unavailable) on tests in the "tests" or "test" folder and it will try to figure out where the code to mutate lies. Run

.. code-block:: console

mutmut --help

for the available flags, to use other runners, etc. The recommended way to use mutmut if the defaults aren't working for you is to add a block in setup.cfg. Then when you come back to mutmut weeks later you don't have to figure out the flags again, just run mutmut run and it works. Like this:

.. code-block:: ini

[mutmut]
paths_to_mutate=src/
backup=False
runner=python -m hammett -x
tests_dir=tests/
dict_synonyms=Struct, NamedStruct

You can stop the mutation run at any time and mutmut will restart where you left off. It's also smart enough to retest only the surviving mutants when the test suite changes.

To print the results run mutmut show. It will give you a list of the mutants grouped by file. You can now look at a specific mutant diff with mutmut show 3, all mutants for a specific file with mutmut show path/to/file.py or all mutants with mutmut show all.

You can also write a mutant to disk with mutmut apply 3. You should REALLY have the file you mutate under source code control and committed before you apply a mutant!

Whitelisting

You can mark lines like this:

.. code-block:: python

some_code_here()  # pragma: no mutate

to stop mutation on those lines. Some cases we've found where you need to whitelist lines are:

  • The version string on your library. You really shouldn't have a test for this :P
  • Optimizing break instead of continue. The code runs fine when mutating break to continue, but it's slower.

See also Advanced whitelisting and configuration_

Example mutations

  • Integer literals are changed by adding 1. So 0 becomes 1, 5 becomes 6, etc.
  • < is changed to <=
  • break is changed to continue and vice versa

In general the idea is that the mutations should be as subtle as possible. See __init__.py for the full list.

Workflow

This section describes how to work with mutmut to enhance your test suite.

  1. Run mutmut with mutmut run. A full run is preferred but if you're just getting started you can exit in the middle and start working with what you have found so far.
  2. Show the mutants with mutmut results
  3. Apply a surviving mutant to disk running mutmut apply 3 (replace 3 with the relevant mutant ID from mutmut results)
  4. Write a new test that fails
  5. Revert the mutant on disk
  6. Rerun the new test to see that it now passes
  7. Go back to point 2.

Mutmut keeps a result cache in .mutmut-cache so if you want to make sure you run a full mutmut run just delete this file.

You can also tell mutmut to just check a single mutant:

.. code-block:: console

mutmut run 3

Advanced whitelisting and configuration

mutmut has an advanced configuration system. You create a file called mutmut_config.py. You can define two functions there: init() and pre_mutation(context). init gets called when mutmut starts and pre_mutation gets called before each mutant is applied and tested. You can mutate the context object as you need. You can modify the test command like this:

.. code-block:: python

def pre_mutation(context):
    context.config.test_command = 'python -m pytest -x ' + something_else

or skip a mutant:

.. code-block:: python

def pre_mutation(context):
    if context.filename == 'foo.py':
        context.skip = True

or skip logging:

.. code-block:: python

def pre_mutation(context):
    line = context.current_source_line.strip()
    if line.startswith('log.'):
        context.skip = True

look at the code for the Context class for what you can modify. Please open a github issue if you need help.

JUnit XML support

In order to better integrate with CI/CD systems, mutmut supports the generation of a JUnit XML report (using https://pypi.org/project/junit-xml/). This option is available by calling mutmut junitxml. In order to define how to deal with suspicious and untested mutants, you can use

.. code-block:: console

mutmut junitxml --suspicious-policy=ignore --untested-policy=ignore

The possible values for these policies are:

  • ignore: Do not include the results on the report at all
  • skipped: Include the mutant on the report as "skipped"
  • error: Include the mutant on the report as "error"
  • failure: Include the mutant on the report as "failure"

If a failed mutant is included in the report, then the unified diff of the mutant will also be included for debugging purposes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].