knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) source("engine.R")
This guide walks you through your first mutation test run, from setup to interpreting results.
muttest works with R packages with testthat tests out of the box. If you're not using a package structure, or not using testthat, see ?TestStrategy for configuration options.
Start small. Choose one file from R/ that contains meaningful logic — branching, arithmetic, comparisons. Avoid files that are mostly glue code or just call other functions.
A test plan describes what to mutate and which mutations to apply:
library(muttest) plan <- muttest_plan( source_files = "R/is_adult.R", mutators = comparison_operators() )
comparison_operators() is a preset that generates mutants by swapping each comparison operator for related alternatives. For >= it produces two mutants: >= → > and >= → <=.
muttest::muttest(plan, "tests/testthat")
Each column in the progress table means:
| Column | Meaning | | ------ | ----------------------------------------------- | | K | Killed — mutants your tests caught | | S | Survived — mutants your tests missed | | E | Errors — mutants that caused unexpected errors | | T | Total mutants for this mutator/file combination | | % | Mutation score for this row |
The mutation score is Killed / Total × 100%. A ✔ row means at least one mutant was killed; an x row means all mutants survived.
Here is a complete example showing a weak test, the live output, and the fix:
boundary
Start with one file. Aim for a meaningful score improvement each iteration rather than chasing 100% immediately. A score of 80%+ on critical business logic can be a reasonable target to start from.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.