什么是报告框架?

2024-06-29 01:02:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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.

(重点是我的)

当然,我在google上搜索了一下“什么是报告框架”,希望得到一个这么好的问题,但没有看到。那么,在这种情况下,什么是报告框架?你知道吗


Tags: andofthe框架by报告testsunit
1条回答
网友
1楼 · 发布于 2024-06-29 01:02:05

报告框架是测试系统的一部分,负责报告测试结果。当你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生成一个^{},报告系统可以使用它来确定要报告什么,而无需报告系统知道如何实际测试。可以自定义或替换报告代码,而无需重写测试代码。你知道吗

相关问题 更多 >