Mutation testing evaluates how well a test suite can detect changes in source code. If a change (mutation) does not alter the test results, the tests may be ineffective.
- mutmut: Easy-to-use mutation testing system.
- mutation-waterfall: Visualizes mutation landscapes.
- mutpy: (No longer supported) Mutation testing tool for Python.
- mutation: Pytest integration for mutation testing.
- cosmic-ray: Widely used, long-term support mutation testing tool for Python 3.
Consider:
- Popularity and usage
- Project history and maturity
- Availability of support/extensions
- Long-term maintenance
- Used in diverse projects.
- Extensive related projects.
- Supports automated and complex test scenarios.
- Long-term support.
Mutation testing modifies code to introduce small errors and checks if the test suite can catch them. Effective tests will detect the mutations; if they don’t, the tests need improvement.
- Python programming knowledge.
- Basic command-line skills.
pip install cosmic-ray- Navigate to the source file.
- Create a configuration file.
- Initialize a session (SQL file).
- Check if the test suite passes on un-mutated code.
- Execute the tests.
- Examine the session.
- Generate an HTML report.
# Create config file
cosmic-ray new-config tutorial.toml
# Initialize session
cosmic-ray init tutorial.toml tutorial.sqlite
# Check un-mutated code
cosmic-ray --verbosity=INFO baseline tutorial.toml
# Execute tests
cosmic-ray exec tutorial.toml tutorial.sqlite
# Generate HTML report
cr-html tutorial.sqlite > report.htmlfrom subprocess import call
# Initialize session
call(["cosmic-ray", "init", "tutorial.toml", "tutorial.sqlite"], shell=True)
# Execute tests
call(["cosmic-ray", "exec", "tutorial.toml", "tutorial.sqlite"], shell=True)
# Generate HTML report
call(["cr-html", "tutorial.sqlite", ">", "report.html"], shell=True)For more details, refer to the live demo.