Extendable mutation testing framework
Project description
Extendable mutation testing framework
What is mutation testing?
Mutation testing provides what coverage tries to, it finds logic that is not covered by your test suite.
It finds such places by applying mutations to your code and running the modified code against your test suite. If the tests succeed with the mutated code, it means the changed expression is likely not covered ny the tests.
In comparison to coverage:
:green_heart: Checks expressions, not lines.
:green_heart: Checks whether the expression is covered, not whether it was executed.
:x: Can find irrelevant mutants (e.g. mutations in logging or performance optimizations or a mutation that does not break the code)
:x: Executes the tests many times and therefore takes much more time.
There are mitigations for these downsides:
:star: We can mutate only lines that have changed in a given PR
:star: We can show the failing mutants via comments/warnings, as opposed to failing the whole CI pipeline.
A much more in-depth explanation about the concept can be found in This blog post by Goran Petrovic
Why use radiation?
Extendability
In my personal experience, trying to integrate mutation testing into your CI pipeline can be a bit challenging. There are a lot of features you might want to customize to mitigate some of the downsides of mutation testing, or to be able to integrate it to your project and dev environment effectively.
For example, ignoring mutations on logging logic (which depends on your logging framework and conventions), or showing the results on various platforms (e.g. github, bitbucket, gitlab).
radiation puts extendability as a top priority so that adding mutation testing to your project is feasible.
How?
Mechine friendly
The core of radiation is a pure python package that can be used by scripts.
The actual CLI uses the core package instead of the logic being coupled to it.
Pluginable
radiation is written as a pipeline, each stage has an interface (e.g. Mutator, MutantFilter, Runner).
Extending the logic is as simple as creating an object or function that matches that (simple) interface.
The radiation CLI utilises entry points so that radiation plugins can be added just by installing them with pip.
Usage
radiation is currently in development, the API might change between versions.
radiation = Radiation(
filters=[PatchFilter.from_git_diff("develop")],
config=Config(project_root=Path("/home/myuser/myproject/")),
)
for path in radiation.find_files("."):
for mutation in radiation.gen_mutations(path):
result = radiation.test_mutation(
mutation,
run_command="pytest",
)
print(result)
or use CLI
Usage: radiation [OPTIONS] COMMAND [ARGS]...
Options:
-c, --config-file PATH configuration file to use [default:
(.radiation.cfg)]
-p, --project-root PATH path to project to run on [default: (cwd)]
-i, --include TEXT paths from which to take files for mutation, can be
globs
--run-command TEXT command to run to test a mutation [default:
(pytest)]
--help Show this message and exit.
Commands:
run run the mutation testing pipeline
Roadmap
- Add Basic CLI
- Improve output in CLI
- Support PatchFilter in CLI
- Use
parso
instead of the built-inast
for cross-version mutations. - Add wrapper class for remote components (i.e.
RemoteFilter(hostname)
,RemoteRunner(hostname)
). - Add Output component (with
JunitXMLOutput
,GithubOutput
,BitbucketOutput
builtins) - Add Cache component (with
FileCache
,MongoCache
builtins) - Add Sorter component (for selecting the most likely to succeed mutations)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file radiation-0.2.0.tar.gz
.
File metadata
- Download URL: radiation-0.2.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.8.0-59-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88d4f36c72229c432e71d2c98a69618439e61445e498b162e5679d443336b0c4 |
|
MD5 | 5027b113aef3e026feec01de2ad037e8 |
|
BLAKE2b-256 | b7fde4defabd1b056950bab269e3abc9978629949143dd0e3da263f6326f043a |
File details
Details for the file radiation-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: radiation-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.8.0-59-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c3a30f835c60d022f41a9664fcdbc72df2c2dd5497ee688ac718887fd09a8b |
|
MD5 | f1f19456fc8384bb3ce8c45dc4c1ce2a |
|
BLAKE2b-256 | f812d94bb41055bc69a2727889cec64cca2e355b5b55aab59e50ad53655153e9 |