开发者

Should one use TestCase or FunctionTestCase for testing in python?

开发者 https://www.devze.com 2023-03-13 13:43 出处:网络
While trying to get a hunch of TDD in python I encountered the FunctionTestCase class. I understand, that it defi开发者_开发百科nes equivalent functions to the TestCase classes.

While trying to get a hunch of TDD in python I encountered the FunctionTestCase class. I understand, that it defi开发者_开发百科nes equivalent functions to the TestCase classes.

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

Is there a significant difference in using FunctionTestCase or is it a question of flavour?


FunctionTestCase can be used for easily reusing existing code. More often that not you will probably be using the TestCase class.

From unittest documentation:

Some users will find that they have existing test code that they would like to run from unittest, without converting every old test function to a TestCase subclass.

For this reason, unittest provides a FunctionTestCase class. This subclass of TestCase can be used to wrap an existing test function. Set-up and tear-down functions can also be provided.

0

精彩评论

暂无评论...
验证码 换一张
取 消