DEV Community

loading...

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

Collapse
bugsysailor profile image
Bugsy Sailor

I apologize, but can you explain what "code coverage" is? #newb

Collapse
storrence88 profile image
Steven Torrence

It's a term for what percentage of your app is covered by tests.

Collapse
patryktech profile image
Patryk

You can see an example report coverage here, from one of my projects.

When I push my project to gitlab, Gitlab-CI runs my test suite, and says which lines were hit by the test run, and which were missed in each file (total coverage is 90%).

For instance, it can tell you that your tests cover only one branch (e.g. the if), but not another (the matching else), or if one of your functions isn't covered at all.

Collapse
bugsysailor profile image
Bugsy Sailor

Thank you.

Thread Thread
patryktech profile image
Patryk

No problem. If you're not familiar with testing, I'd encourage you to look at unit testing tutorials for the language you work with.

For JavaScript, I love jest. For Python, pytest is great. They both support coverage reports, though I'm not sure if jest generates one as HTML or only in the CLI.

There's plenty of tutorials on YouTube, probably some on here too.