python - 什么是报告框架?

标签 python unit-testing python-unittest

阅读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/

相关文章:

python - Django i18n 查找支持的语言

python - 如何根据比较两列中的值来组合 pandas 数据框中的行?

python - Mysql 查询在 python 中自动终止

unit-testing - 如何测试 setTimeout 是否被正确调用?

android - 无法使用 MockServerResponse 读取 Json 文件

python - 如何使用 python 3.8 unittest IsolatedAsyncioTestCase 处理 CancelledError

python - 修补时,assert_called_once 在应该失败时不会失败

python - 用python(scipy.odr)在正交回归中遇到除以零

java - 单元测试用例中的空 @Autowired beans

Python单元测试: Unit test the message passed in raised exception