DEV Community

Discussion on: Achieving 100% code coverage will make you a better developer. Seriously.

Collapse
 
nombrekeff profile image
Keff

Take this post for example:

He has a cool example showing 100% code coverage does not mean good or correct code is being tested:


Here, we call GetAnswerString with 2 and 2. This method should give us back “The answer is 4”.
Unfortunately, the developer didn’t really do addition and the method always returns “The answer is 42”.

Unfortunately, the unit tests are just built to ensure that the string starts with the expected prefix, so the actual value isn’t tested.

As a result, we have 100% passing tests and a blatantly incorrect method.

Just because a line is executed by a test, doesn’t mean that the line is correct or accurately tested.
@integerman