Haskell 中的突变测试
Mutation Testing in Haskell

原始链接: https://cs-syd.eu/posts/2026-06-03-mutation-testing-in-haskell

**Sydtest** 现已全面支持变异测试。该功能通过自动向代码中引入“变异”,并验证测试套件能否识别出这些变异,从而提供了一种评估测试质量的稳健方法。 从功能上讲,如果代码被修改后测试套件依然通过(即“变异存活”),则说明测试覆盖存在漏洞;如果测试失败(即“变异被杀灭”),则说明测试覆盖有效。在人工智能生成代码的时代,代码产出量往往超过了人工审查和传统测试方法的承载能力,这种客观、自动化的流程显得尤为重要。通过实施这种独立于 AI 的检查机制,开发者可以确保代码得到真正的验证,而非仅仅看起来正确。 Sydtest 与 Nix 无缝集成,开发者可直接将变异检查添加到 `flake.nix` 中。该工具提供人类可读和机器可读两种格式的报告,并支持通过注解排除对非关键代码(如调试日志)的测试。随着人工智能在开发领域的普及,变异测试提供了一种必要的“完整性检查”,以确保测试套件始终保持可靠且全面。

```Hacker News新帖 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交登录Haskell 中的变异测试 (cs-syd.eu)12 分,Norfair 1 小时前 | 隐藏 | 过往 | 收藏 | 讨论 帮助 准则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索: ```
相关文章

原文

Mutation testing is now generally available in sydtest. This is a major step towards a saner development workflow in the age of AI-generated code.

What is mutation testing?

Mutation testing aims to improve a test suite by automatically mutating code and asserting that the tests start failing.

Alternatively:

Mutation testing is like a type-system for your tests. It asserts that the tests test the code thoroughly.

Example

Consider this simple function:

non-AI-based CI system that tells me when any of my checks fail.

So my aim was to produce a check that would fail if a change were insufficiently tested, without relying on any subjective criterion for determining what "sufficient testing" means. Mutation testing lets me have a completely objective criterion that is independent of my project defined in another repository so that my agent cannot cheat.

How can I try it?

Mutation testing is now officially available as a part of Sydtest.

Nix Check

You can add a mutation check to your flake.nix's checks like this:

NixCI and the latest version of really-safe-money is already fully mutation tested.

Please let me know if you end up trying it. I'd love to nerd out about this.

联系我们 contact @ memedata.com