NewsCrawler.org

Mutation testing: checking test quality by changing code on purpose

おい、 Mutation Test をやれ。テスト品質を、測るために
Image: zenn.dev

Coverage shows which lines ran during tests, but not whether the tests notice when the code changes. Mutation testing changes source code on purpose, for example replacing > with < or >=, and runs the tests on each changed version, called a mutant[1]. If the tests fail, the mutant is Killed[3]; if all tests still pass, it Survived, meaning the tests missed the change. Some mutants behave exactly like the original code for every input, so no test can catch them; these are equivalent mutants[2].

The author suggests using it to measure the quality of unit tests rather than integration tests, because each mutant reruns the related tests, so slow tests make the run slow. It does not need to run on every CI build; it works better as a refactoring tool, run only on changes, for example with --since HEAD or --since main. The results can also point to candidates for dead code.

The author built @mizchi/mutator as a faster alternative to the existing StrykerJS[4] for projects that use Vitest, and it requires Node.js 24 or later and Vitest 5. It is installed with pnpm add -D @mizchi/mutator and run with pnpm exec mutator. Reports are written to .mutator/report/index.html and .mutator/report/mutation.json.

Read the original zenn.dev

Sources

  • Zenn JA

    おい、 Mutation Test をやれ。テスト品質を、測るために

    473 likes177 bookmarks1 comment

Published: First seen: Читать по-русски

Open as a page