Mutation Test Harness
Coverage percentage answers "did this line run", not "would a test fail if this line were wrong". A test suite can reach 100% line coverage of a function and still let a flipped comparison or an off-by-one threshold ship, if none of its inputs happen to land near the boundary the mutation would break. Mutation testing answers the sharper question directly: inject one real defect at a time and check whether any test in the suite goes red. A mutant the suite fails to kill is a test gap disguised as full coverage. MQL4 has no runtime #ifdef and no function pointers, so a single compiled program cannot swap in a genuinely different function body per mutant the way a language with reflection or dynamic dispatch could. This header's practical substitute is a set of mutation primitives - MutationCompareGreater(), MutationCompareLess(), MutationThreshold(), MutationBool(), MutationValue() - each of which behaves correctly for MUTATION_NONE and applies exactly one deliberate defect (a flipped comparison, an inverted comparison, an off-by-one constant, a negated boolean, a constant forced to zero) for its own ENUM_MUTATION_KIND, and is a silent no-op for every other kind. A system under test routes its comparisons and constants through these calls instead of the raw operators, and one input flag then switches its whole behaviour per pass. The demo makes the point concrete rather than abstract: a WEAK test suite with no boundary case reaches full line coverage of the function under test, yet its mutation score is only 60% - a flipped comparison and an off-by-one threshold both survive undetected. A STRONG suite that adds one exact-boundary case and one just-past-boundary case kills every mutant. That gap between "100% coverage" and "60% mutation score" is the whole reason mutation testing exists. Notes and limitations - This is a manual mutation framework, not source-level automatic mutation. Only call sites that were deliberately routed through a MutationXxx() primitive can be mutated - a raw ">" left in the system under test is invisible to this header. - Each primitive applies only ONE mutation kind at a time and is a no-op for every other kind, by design - this keeps each mutant isolated (classic single-fault mutation testing) rather than compounding several defects into one confusing pass. - The scorecard registry is capped at 64 entries (MUTATIONHARNESS_MAX_RESULTS). - A mutant that survives every test in a suite is not automatically a bug in the mutant list - it is a report that the suite has a gap at that specific boundary, which is the actionable signal this header produces.
Script · MT4 · v1.0 · Free
About Mutation Test Harness
Mutation Test Harness is a script for MetaTrader 4. It has 1 setting, such as Off by one delta. MQL source code included.
Files in the download: MutationTestHarness.mqh, MutationTestHarness.txt, MutationTestHarnessDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Off by one delta | 1.0 | Threshold nudge used by the MUTATION_OFF_BY_ONE mutant |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code