What is coverage
1 Intro
When building a Django app, It's nice to know which of your files miss testing.
At least the first time you are writing tests, you are not sure what you should cover.. coverage shows you just that. Informs you in percentage, how much of your code is covered with test. Not only that, it will show you what exact parts of your code are covered and which ones are not yet covered.
Here is an example how to run coverage for a django app:
pip install coverage coverage run manage.py test coverage report coverage html
Now you can check the html folder content to see your coverage results.
2 Run coverage before each commit with pre-commit
Later, if you want to force yourself to write tests for each new feature, to keep that coverage at +95%, you can implement coverage into your pre-commit (what is pre-commit?).
NOTE: not using pre-commits, since they are quite time consuming.
Run a github action instead and be notified if something breaks with an email.
3 Run coverage after each commit with github actions
Wrote a separate post about this - here.