阅读unittest它说:
The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework.
(强调的是我的)
我当然在谷歌上搜索了“什么是报告框架”,期待一个这样的问题,但没有看到。那么,在这种情况下,报告框架是什么?
最佳答案
报告框架是测试系统的一部分,负责报告测试结果。当你 run a test :
import unittest
class MyTest(unittest.TestCase):
def test_good(self):
pass
def test_bad(self):
self.assertTrue(False)
if __name__ == '__main__':
unittest.main()
并查看输出:
F.
======================================================================
FAIL: test_bad (__main__.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./prog.py", line 7, in test_bad
AssertionError: False is not true
----------------------------------------------------------------------
Ran 2 tests in 0.000s
FAILED (failures=1)
报告框架获取有关通过、失败和异常的原始数据,并生成您看到的输出。
unittest
将其与直接负责测试功能的系统部分以及负责收集和运行测试的系统部分分开。运行 TestCase
会生成 TestResult
报告系统可以使用它来确定要报告的内容,而报告系统不需要知道如何实际测试事物。报告代码可以自定义或替换,无需重写测试代码。
关于python - 什么是报告框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49640451/