django测试覆盖率与黑匣子测试? [英] django test coverage with black box testing?

查看:79
本文介绍了django测试覆盖率与黑匣子测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用黑盒(功能集成)测试方法来测试Django应用程序,其中客户端使用对Django应用程序的REST API调用来执行测试.客户端在不同的VM上运行,因此我们不能使用典型的coverage.py(我认为).

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).

是否有一种方法可以计算这些黑盒测试的覆盖率?我可以以某种方式指示Django在测试覆盖率模式下启动和停止,然后报告测试覆盖率吗?

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?

推荐答案

功能集成测试的覆盖范围实际上与单元测试的覆盖范围不同,后者涵盖了已执行的代码行.您可能更关心真正的黑盒测试中用例的覆盖范围.

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.

但是,无论如何,如果您一直在寻找代码覆盖率(并且确实有某些原因,可能需要这样做),如果可以访问服务器来设置测试方案,则看起来应该可以使用coverage.py.您将需要实现一种结束django流程的方法,以允许coverage.py编写覆盖率报告.

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.

发件人: https://coverage.readthedocs.io/en/coverage-4.3.4/howitworks.html#execution

在执行结束时,coverage.py将收集到的数据写入数据文件"

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

这表明python进程必须自然完成.手动终止该进程也将导致coverage.py包装器无法写入.

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.

一些结束django的想法:使用sys.exit()停止django命令

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

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

这篇关于django测试覆盖率与黑匣子测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆