Hacker News new | ask | show | jobs
by bluecheese452 35 days ago
Also what is 100% test coverage?

If I have a function add_nums that takes 2 numbers and adds them, there are like infinite inputs that can be tested.

If I have a function shape_color that can take circle, triangle, square for the shapes and red, blue, for the colors, then there are 6 different states. But what if my function just returns if it is a circle or triangle. It only cares about 2 different color paths when it is a square. Do I test all 6 states or do I test only the 3 code paths?

I think code coverage like many things is a “it depends”.

2 comments

I think 100% code coverage usually means that for every branch, there is some test that results in it going down that branch? Like, there’s no line of code (outside of potential exception handling code?) that isn’t “tested” by any test (where “tested” means “it gets run during the test”).
>> If I have a function add_nums that takes 2 numbers and adds them, there are like infinite inputs that can be tested.

That's what formal verification is for: you generate math statements from the code, and then prove them.

Testing is for covering the most common scenarios and likely edge cases. 100% coverage means every line of code in the app is executed when your test suite runs. It is useful as a bare minimum, but by itself does not guarantee that there are no bugs.