【问题标题】:Should one use TestCase or FunctionTestCase for testing in python?应该使用 TestCase 还是 FunctionTestCase 在 python 中进行测试?
【发布时间】:2011-06-17 15:39:34
【问题描述】:

在尝试在 python 中获得 TDD 预感时,我遇到了 FunctionTestCase 类。我理解,它定义了与 TestCase 类等效的函数。

assertEqual = failUnlessEqual(self, first, second, msg=None)
assertNotEqual = failIfEqual(self, first, second, msg=None)
# and so on...

使用FunctionTestCase有显着差异还是口味问题?

【问题讨论】:

    标签: python python-unittest testcase


    【解决方案1】:

    FunctionTestCase 可用于轻松重用现有代码。更多时候,你可能会使用TestCase 类。

    来自unittest documentation

    有些用户会发现他们有 现有的测试代码,他们将 喜欢从单元测试运行,没有 将每个旧的测试函数转换为 一个 TestCase 子类。

    因此,unittest 提供了一个 FunctionTestCase 类。这个子类 TestCase 可用于包装一个 现有的测试功能。设置和 拆卸功能也可以 提供。

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 2012-08-23
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2020-03-19
      相关资源
      最近更新 更多