Try out mutation testing #1022
Labels
ci
enhancement
evaluation needed
proposal needs to be validated or tested before fully implementing it in k6
help wanted
tests
The idea behind mutation testing (as I understand it) is that in a lot of cases just because you have 100% coverage and tests for everything you have imagined, doesn't mean that part of your code are actually tested. Mutation testing runs the tests without any changes and then starts introducing random changes to the codebase and rerunning the tests. It is expected that changing the code will change the output of the test cases. If it doesn't then the made mutation is considered to be undetected bug.
The unfortunate reality is that there are a LOT of false positives especially if you do any kind of optimization. For example a simple min function
A possible mutaton in this code is for the
if a[i] < min
to becomeif a[i] <= min
but the output wont change ... which I would not consider a bug. This is the same for any such optimization.Looking at awesome-mutation-testing there is currently only one not abandoned mutation testing tool for golang go-mutesting which is not all that active as well.
The awesome-mutation-testing has links to some articles and thesis that are probably good idea to be read while/when/if we try mutation testing.
My original try of go-mutesting shows that it somewhat not fast enough for automatic testing but probably is good enough for some prerelease testing and maybe running it locally every month/week or something like that.
I did try it on the stats package by running
inside of the stats package
the end result is
which took 16 minutes 39 seconds. I intend on running it on the whole codebase during the weekend (as it will probably take hours if not days). The end score of 0.27 is ... bad but also a lot of the failed mutations are because of optimizations
or log statements
also the package in question has 71% coverage which probably means that a lot of the reported mutations are for code that is not covered where whatever change is made as long as it compiles it will give the same result as previously.
Also unfortunately the current blacklsting of changes is through a file with the md5sum of the change that should not be tested ... which as is mentioned in the documentation will mean that if the source code changes some of those md5sums will no longer be true.
Another problem with go-mutesting is the fact that you will need to read it output to see what changes failed and copy-paste the patch and apply it yourself which can be somewhat time consuming :(.
With everything here said I think it is still good idea to do some more testing and maybe search for better ways to blacklist changes we don't care about. I doubt that we will ever put this in the CI/CD pipeline but maybe we can run it every month or when making huge changes such as #1007 to see if the new tests actually cover a lot of the corner cases. Unfortunately it also needs high test coverage as all not covered lines will produce errors. There is an issue to make go-mutesting coverage aware but there is no movement as far as I can see.
I am going to look through the reported issues and see if I can find some that are covered but mutation the code still produces errors.
The text was updated successfully, but these errors were encountered: