应该使用TestCase或FunctionTestCase在python中进行测试吗?

Auf*_*ind 2 python testcase python-unittest

在尝试在python中获得TDD的预感时,我遇到了这个FunctionTestCase类.我明白,它定义了TestCase类的等效函数.

assertEqual = failUnlessEqual(self, first, second, msg=None)
assertNotEqual = failIfEqual(self, first, second, msg=None)
# and so on...
Run Code Online (Sandbox Code Playgroud)

使用中是否存在显着差异,FunctionTestCase或者是味道问题?

Bry*_*yan 6

FunctionTestCase可用于轻松重用现有代码.更常见的是,您可能不会使用该TestCase课程.

来自unittest文档:

一些用户会发现他们现有的测试代码是他们想要从unittest运行的,而不是将每个旧的测试函数转换为TestCase子类.

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