<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://davidollerhead.com">
  <title>David Ollerhead - Notes</title>
  <subtitle>David Ollerhead - Front End focused Engineering Manager</subtitle>
  <link href="https://davidollerhead.com/feed.xml" rel="self"/>
  <link href="https://davidollerhead.com/notes/"/>
  <updated>2026-11-19T00:00:00Z</updated>
  <id>https://davidollerhead.com/notes/</id>
  <author>
    <name>David Ollerhead</name>
  </author>
  <entry>
    <title>Mutation testing</title>
    <link href="https://davidollerhead.com/notes/mutation-testing/"/>
    <updated>2026-11-19T00:00:00Z</updated>
    <id>https://davidollerhead.com/notes/mutation-testing/</id>
    <content xml:lang="en" type="html">&lt;div class=&quot;placeholder-notice&quot;&gt;
  &lt;strong&gt;Placeholder copy:&lt;/strong&gt; This note is a temporary placeholder. The full post on mutation testing will replace this text later.
&lt;/div&gt;
&lt;p&gt;Line coverage tells you which lines of code executed while your tests ran, not whether your assertions would actually notice if those lines behaved differently.&lt;/p&gt;
&lt;p&gt;Mutation testing addresses that gap by making small, automated changes (mutants) to your source code, such as flipping conditionals, changing arithmetic operators, or removing return values, and re-running the test suite against each mutant. If the tests still pass, the mutant &lt;em&gt;survived&lt;/em&gt;, pointing to a blind spot in your assertions.&lt;/p&gt;
&lt;p&gt;Consider a simple boundary check:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes catppuccin-latte tokyo-night&quot; style=&quot;background-color:#eff1f5;--shiki-dark-bg:#1a1b26;color:#4c4f69;--shiki-dark:#a9b1d6&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#7DCFFF&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#BB9AF7&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt; isEligibleForDiscount&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt;quantity&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#0DB9D7&quot;&gt; number&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#0DB9D7&quot;&gt; boolean&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-light-font-style:italic;--shiki-dark:#51597D;--shiki-dark-font-style:italic&quot;&gt;  // Original condition: &gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-light-font-style:italic;--shiki-dark:#51597D;--shiki-dark-font-style:italic&quot;&gt;  // A common mutant swaps &gt;= for &gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-light-font-style:inherit;--shiki-dark:#BB9AF7;--shiki-dark-font-style:italic&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; quantity&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#BB9AF7&quot;&gt; &gt;=&lt;/span&gt;&lt;span style=&quot;color:#FE640B;--shiki-dark:#FF9E64&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If every test passes &lt;code&gt;quantity = 12&lt;/code&gt; or &lt;code&gt;quantity = 5&lt;/code&gt; and nothing exercises &lt;code&gt;quantity = 10&lt;/code&gt;, line coverage stays at 100%, yet the &lt;code&gt;&amp;gt;&lt;/code&gt; mutant survives unnoticed. Adding a boundary test turns that surviving mutant into a caught regression.&lt;/p&gt;
&lt;h2&gt;How it works&lt;/h2&gt;
&lt;p&gt;A mutation testing tool parses your source, applies one small change at a time, and runs the tests that cover the changed code. Each mutant ends up in one of a few states:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Killed:&lt;/strong&gt; at least one test failed, which is what you want.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Survived:&lt;/strong&gt; every test passed, so nothing noticed the change.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Timed out:&lt;/strong&gt; the mutant caused an infinite loop, which usually counts as killed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No coverage:&lt;/strong&gt; no test touched the mutated line at all.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;em&gt;mutation score&lt;/em&gt; is the percentage of mutants killed. Unlike line coverage, it measures whether your tests can detect a change in behaviour, not just whether they ran the code.&lt;/p&gt;
&lt;h2&gt;Common mutators&lt;/h2&gt;
&lt;p&gt;Most tools ship a similar set of mutation operators:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Original&lt;/th&gt;
&lt;th&gt;Mutant&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Conditional boundary&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;gt;= b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;gt; b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Negated conditional&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a === b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a !== b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Arithmetic&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a + b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a - b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logical&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a &amp;amp;&amp;amp; b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a || b&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Return value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;return total&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;return 0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Statement removal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;audit.log(event)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;em&gt;(deleted)&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String literal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;active&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Each of these maps to a real class of bug: off-by-one errors, inverted checks, forgotten side effects, and silently dropped return values.&lt;/p&gt;
&lt;h2&gt;A second example&lt;/h2&gt;
&lt;p&gt;Boundary conditions are the classic case, but removed side effects are just as common:&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes catppuccin-latte tokyo-night&quot; style=&quot;background-color:#eff1f5;--shiki-dark-bg:#1a1b26;color:#4c4f69;--shiki-dark:#a9b1d6&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#7DCFFF&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color:#8839EF;--shiki-dark:#BB9AF7&quot;&gt; function&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt; checkout&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt;cart&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#DF8E1D;--shiki-light-font-style:italic;--shiki-dark:#C0CAF5;--shiki-dark-font-style:inherit&quot;&gt; Cart&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt; payments&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#DF8E1D;--shiki-light-font-style:italic;--shiki-dark:#C0CAF5;--shiki-dark-font-style:inherit&quot;&gt; PaymentGateway&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt; audit&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#DF8E1D;--shiki-light-font-style:italic;--shiki-dark:#C0CAF5;--shiki-dark-font-style:inherit&quot;&gt; AuditLog&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-light-font-style:inherit;--shiki-dark:#9D7CD8;--shiki-dark-font-style:italic&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#BB9AF7&quot;&gt; total&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; cart&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;reduce&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt;sum&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#E64553;--shiki-light-font-style:italic;--shiki-dark:#E0AF68;--shiki-dark-font-style:inherit&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#BB9AF7&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; sum&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;price&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;quantity&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#FE640B;--shiki-dark:#FF9E64&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt;  payments&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;charge&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt;cart&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; total&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt;  audit&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#9ECE6A&quot;&gt;checkout&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#73DACA&quot;&gt; customerId&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; cart&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;customerId&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; total&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-light-font-style:inherit;--shiki-dark:#BB9AF7;--shiki-dark-font-style:italic&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; total&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If your tests only assert on the returned &lt;code&gt;total&lt;/code&gt;, a mutant that deletes the &lt;code&gt;audit.record(...)&lt;/code&gt; call survives. The behaviour changed, compliance would be unhappy, and every test is still green. Asserting that the audit log received the expected entry kills it.&lt;/p&gt;
&lt;pre class=&quot;shiki shiki-themes catppuccin-latte tokyo-night&quot; style=&quot;background-color:#eff1f5;--shiki-dark-bg:#1a1b26;color:#4c4f69;--shiki-dark:#a9b1d6&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;it&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#9ECE6A&quot;&gt;records an audit entry for each checkout&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; ()&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#BB9AF7&quot;&gt; =&gt;&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8839EF;--shiki-light-font-style:inherit;--shiki-dark:#9D7CD8;--shiki-dark-font-style:italic&quot;&gt;  const&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#BB9AF7&quot;&gt; audit&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#73DACA&quot;&gt; record&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; vi&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;  checkout&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt;cartWithTwoItems&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; fakeGateway&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt; audit&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;  expect&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#C0CAF5&quot;&gt;audit&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#7DCFFF&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#1E66F5;--shiki-light-font-style:italic;--shiki-dark:#7AA2F7;--shiki-dark-font-style:inherit&quot;&gt;toHaveBeenCalledWith&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#9ECE6A&quot;&gt;checkout&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#73DACA&quot;&gt;    customerId&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#9ECE6A&quot;&gt;cust_123&lt;/span&gt;&lt;span style=&quot;color:#40A02B;--shiki-dark:#89DDFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#73DACA&quot;&gt;    total&lt;/span&gt;&lt;span style=&quot;color:#179299;--shiki-dark:#89DDFF&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#FE640B;--shiki-dark:#FF9E64&quot;&gt; 45&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;  }&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#9ABDF5&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#4C4F69;--shiki-dark:#9ABDF5&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#7C7F93;--shiki-dark:#89DDFF&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Running it in practice&lt;/h2&gt;
&lt;p&gt;Mutation testing is expensive. A suite that takes a minute to run might need to run hundreds of times, once per mutant. A few habits keep it practical:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Scope it.&lt;/strong&gt; Start with a single module or a critical directory rather than the whole repository.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Run incrementally.&lt;/strong&gt; Only mutate files changed in the current branch and cache results between runs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use coverage data.&lt;/strong&gt; Skip mutants on lines no test executes; they will trivially survive and add noise.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Run in CI on a schedule.&lt;/strong&gt; A nightly or weekly full run is often a better fit than blocking every pull request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parallelise.&lt;/strong&gt; Mutants are independent, so they split cleanly across workers.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Reading the results&lt;/h2&gt;
&lt;p&gt;A surviving mutant is a question, not a verdict. Before writing a new test, ask:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Is this a genuine gap in my assertions?&lt;/li&gt;
&lt;li&gt;Is the mutant &lt;em&gt;equivalent&lt;/em&gt;, meaning it changes the code without changing observable behaviour (for example, &lt;code&gt;i &amp;lt; 10&lt;/code&gt; versus &lt;code&gt;i != 10&lt;/code&gt; in a loop that always exits earlier)?&lt;/li&gt;
&lt;li&gt;Is the code itself dead, and should it simply be deleted?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Equivalent mutants are the main source of false positives. You can&#39;t eliminate them entirely, which is why chasing a 100% mutation score is rarely worth it. A score in the 70–85% range on important code is a healthy target for many teams.&lt;/p&gt;
&lt;h2&gt;Where it fits&lt;/h2&gt;
&lt;p&gt;Mutation testing doesn&#39;t replace code coverage, property-based testing, or code review. It complements them by answering a different question: &lt;em&gt;if this code were wrong, would my tests tell me?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Used selectively on the logic that matters most, such as pricing, permissions, and data transformations, it tends to surface a handful of high-value missing assertions rather than a mountain of busywork. That is usually enough to justify the runtime.&lt;/p&gt;
&lt;h2&gt;Further reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The documentation for your language&#39;s mutation testing tool, such as Stryker for JavaScript and TypeScript, PIT for Java, or mutmut for Python.&lt;/li&gt;
&lt;li&gt;Research on the &lt;em&gt;coupling effect&lt;/em&gt;, which argues that tests that catch simple mutants also tend to catch more complex faults.&lt;/li&gt;
&lt;li&gt;Your own test suite: pick one critical function, mutate it by hand, and see whether anything fails.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
</feed>
