I was thinking about unit tests and code coverage, and I came up with this thought:
It is possible to have 100% code coverage and not test 100% of your code.
For example:
function myTestedFunction(){
doSomething();
doSomethingElse();
}
In this example, if I have a test that myTestedFunction
calls doSomething
, doSomethingElse();
will count as tested, even though it's not. Is there some way or library that will run your tests with each line removed? I feel like I'm describing it poorly.
I'm using Node.js at the moment, but I'm more curious if something like this exists.
So does anybody know of such a thing?
Thanks!
1 Answer 1
What you're talking about is called mutation testing, and there are a number of implementations available. I've not tried either, but there are at least two javascript versions:
-
I was coincidentally just reading up on mutation testing the other day. Dave Marshall gives a very good introduction to mutation testing.Awemo– Awemo2015年01月11日 20:46:37 +00:00Commented Jan 11, 2015 at 20:46
-
Explore related questions
See similar questions with these tags.
assert
s from your tests, the tests will still execute the exact same code as before, so you will get the exact same coverage, but you will test absolutely nothing. Code coverage tells you what's executed, not what's tested. It can only tell you what's definitely not tested, namely what's not being executed.