django test coverage with black box testing?

。_饼干妹妹 提交于 2021-01-27 13:00:25

问题


We are testing a Django applications with a black box (functional integration) testing approach, where a client performs tests with REST API calls to the Django application. The client is running on a different VM, so we can not use the typical coverage.py (I think).

Is there a way to compute the coverage of these black box tests? Can I somehow instruct Django to start and stop in test coverage mode and then report test coverage?


回答1:


The coverage for functional integration tests are really a different layer of abstraction than unit test coverage which covers lines of code executed. You likely care more about coverage of use-cases in a true black-box test.

But if you are looking for code coverage anyways (and there are certainly reasons why you might want to), it looks like you should be able to use coverage.py if you have access to the server to set up test scenarios. You will need to implement a way to end the django process to allow coverage.py to write the coverage report.

From: https://coverage.readthedocs.io/en/coverage-4.3.4/howitworks.html#execution

"At the end of execution, coverage.py writes the data it collected to a data file"

This indicates that the python processes must come to completion naturally. Killing the process manually would also take out the coverage.py wrapper preventing the write.

Some ideas to end django: stop django command using sys.exit()

See: https://docs.djangoproject.com/en/1.10/topics/testing/advanced/#integration-with-coverage-py



来源:https://stackoverflow.com/questions/21522103/django-test-coverage-with-black-box-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!