TGViewer
ITGram ITGram @itgram_channel · 390 subscribers
Post #612 1.3K
Mutation testing is technique for evaluating how good your tests are. The idea is that a special tool (or a very bored human) breaks the code by slightly changing ("mutating") something in it and then running all the tests, and the tests must fail. If they don't fail, you either have dead code or the tests aren't good enough.

There are some pre-requisites for when it mkes sense to do that:

1. The test coverage is 100%. If it's not, you already know what you should write tests for.
2. The tests are fast.
3. The tests are reliable.
4. The codebase is small.

mutmut is a tool for mutation testing of Python code. You simply point it to the directory with the code, directory with the tests, and what command to use to run the tests, and it will do the rest. When it's done, you can generate an HTML report with the list of diffs of mutations for each file that weren't detected by the tests.

I think it's an "advanced" testing technique. I use it not that often and only on small projects that need to be reliable. There are quite a few "false positives" (things that you can't and shouldn't test, like databse connection options), but from my experience it also a very reliable way to detect what tests you're missing.

#python
More from @itgram_channel
  1. Jul 26, 2023taplo is a CLI tool (and a Rust library) for working with TOML. It can check TOML files fo…
  2. Jul 19, 2023refurb is yet another linter for Python. What makes it special is that it internally runs…
  3. Jul 18, 2023To make all my content accessible, I've provided source, website, and RSS for every projec…
  4. Jul 17, 2023A long time ago, I used to use Twitter to find out about new projects and blog posts. Late…
  5. Jul 17, 2023Channel photo updated
  6. Jun 23, 2023Go 1.21rc1 is released! It's not a final release yet, but we already can see what new feat…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →