DEV Community

Discussion on: Do you aim for 80% code coverage? Let me guess which 80% you choose...

Collapse
 
patryktech profile image
Patryk

Test coverage doesn't really mean much, and every situation is different.

In a library I wrote, I use a Python dict to store a bunch of lambda functions, and have another function that gets one and calls it.

Just because the code is "covered" it doesn't mean that there are no bugs in it. (Of course, I have tests that give me confidence that it works, as I've used TDD to write those rules and test each function extensively).

As far as pytest is concerned, if it hits the dict definition, that code is covered. It doesn't care about calling the lambda functions.

As it's a reusable library, I really like testing it extensively - and it's very easy to get to 100%.

If I work on a website / web app, I will test some back-end things in pytest, some front-end in jest, and some in cypress, and worry more about being confident in my tests than getting to some magic threshold.

Collapse
 
miniscruff profile image
miniscruff

Agree, code coverage to me is a sanity check in things I may have missed. But TDD or similar helps give me the confidence I need.

Having a test cover a line of code is not as good as being confident it works. But, I know if it's not covered I am not confident at all it works.

Collapse
 
patryktech profile image
Patryk

I may be reasonably confident something works even without automated testing. My threshold for acceptable confidence varies on whether something is a side project, or an app that handles customer payments, or if I'm prototyping as opposed to writing production code.

Sometimes, manual testing is good enough for me... Context is important.

I do love automated testing, for the record, and think it's important. Just be pragmatic about it.

Thread Thread
 
miniscruff profile image
miniscruff

Sure, I tend to skip testing entirely for the first release. Gotta get something out there first.

I also accept manual testing IF you only have like 2 end points but probably only for a single update or temp fix. Long term nothing beats automated tests.