Number of lines(*) executed by the tests
---------------------------------------- x 100
Total number of lines(*) in the code
* Not only lines but also functions, branches and statements
- 20% of the code was not executed (Not tested at all)
- 80% of the code was executed (There is a non-zero chance of having it properly tested)
- Common issues:
- Important scenarios not covered
- Testing mocks instead of the actual code
- Biased tests
- Bugs in test code
- Common issues:
- They should detect changes made to the code
- Analysing each test
- Mutation testing
- Introduce one single change to the code (mutant)
- Run the tests
- Analyse
- Tests fail ❌: The change was detected (mutant killed 👍 )
- Back to step 1
- Tests pass ✅: The change as not detected (mutant survived 👎 )
- Add tests to detect the changes
- Back to step 1
- Tests fail ❌: The change was detected (mutant killed 👍 )
We can rely on several frameworks for the most relevant programming languages. They will make a copy of the code base for every change they introduce based on their mutator libraries and run all the tests for each one.
Examples of mutation testing frameworks
- JavaScript: Stryker Mutator
- Java: PIT Mutation Testing
- Pipeline
- Do not run it in the main pipeline
- Run over the weekend
- Local
-
Mutate only the files you're changing
$ npm run mutation:diff > mutation-testing@1.0.0 mutation:diff > git diff --name-only '*.js' | grep -v .spec.js | tr '\\n' ',' | xargs stryker run --mutate -
Run only the tests that cover the changes
-
- Node - v12.16.3
- Npm - 7.6.0
npm install
npm test
npm run mutation
