How can I get the code coverage report for my Unit Test Cases?

How can I get the backend code coverage report for my unit test cases?

I run the below command for unit test case

bench run-tests

& check how many test cases are passed and how many are failed, but I want to check how many lines are covered in unit test cases; I want to see the code coverage report in percentage or in numbers.
There is a tool called Cypress, but that is the front-end testing tool and is not useful for us.

I’ve already checked how to generate a code coverage report in HTML format, but I couldn’t find any way to get that done in official Frappe documentation.

Can anyone help me out with this?

Thank you

2 Likes

bench run-tests --coverage

You can find a sample config here (Frappe HR app): hrms/ci.yml at 8fad1e339edcff7919dde7e01d2d2079d693d714 · frappe/hrms · GitHub

We use coverage.py which is pretty much norm in python coverage reporting. Once you get coverage output you can generate HTML report or just push it to some coverage reporting tool like codecov or coveralls.

Make sure to do bench setup requirements --dev in test environment to install additional dependencies.

1 Like