![]() ![]() Use the python -m coverage run -m unittest command to gather coverage data and the python -m coverage report command to generate a coverage report.Therefore, the test coverage is 10/11 ~ 91%.įinally, click the circle.py module for the detailed report: Summary The test executes 10 of them and misses one statement. ![]() This is because the perimeter() method is not tested.Īfter that, generate the coverage report in HTML format: python -m coverage html The coverage now is 98% in total and 91% in the shape\circle.py module. TOTAL 52 1 98% Code language: plaintext ( plaintext ) Then, generate the coverage report by executing the following command: python -m coverage report Next, gather the coverage data by running the following command: python -m coverage run -m unittest If you open the index.html file of the htmlcov folder, it’ll look like the following: Examining unittest coverage detailed reportįirst, add the perimeter() method to the Circle class as follows: import mathĬlass Circle (Shape): def _init_ (self, radius: float) -> None: if radius float: return math.pi * math.pow(self._radius, 2)ĭef perimeter (self) -> float: return 2 * math.pi * self._radius The output indicates the location of the HTML coverage report htmlcov\index.html under the project folder. Output: Wrote HTML report to htmlcov\ index. To generate the coverage report in HTML format, you change the option of the coverage module to HTML like this: python -m coverage html TOTAL 50 0 100% Code language: plaintext ( plaintext ) Second, turn the coverage data into a report: python -m coverage report To generate a coverage report, you need to carry out two steps:įirst, run the coverage module to generate the coverage data: python -m coverage run -m unittest Note that you can get the source code from this tutorial. We’ll use the following project structure to demo the unittest coverage. In other words, a test suite with high coverage can still be of poor quality. For example, 100% test coverage is not a guarantee that you have a good test suite. If the test coverage is low e.g., 5%, it is an indicator that you’re not testing enough. The test coverage is often used to assess the quality of a test suite. The test coverage is also known as code coverage. Test coverage is a ratio between the number of lines executed by at least one test case and the total number of lines of the code base: test coverage = lines of code executed / total number of lines Summary: in this tutorial, you’ll learn how to use the Python unittest coverage command to generate a test coverage report. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |