Hit9 Blog Wiki Project Links Archives Resumé
Page: First UP Pre Next Back

使用nose进行单元测试

Fork me on GitHub

允许转载, 但转载请注明出处

Date:2012-12-31

最近写了一个python和mysql的orm。需要做一个单元测试

GG下发现,大家都在向nose靠拢。

nose是一个python的单元测试工具,nose会把名字是test或者Test开头的python模块,类,函数当作测试用例。

注意的是:任两个测试用例之间不应该有联系,也不应有顺序关系

以setUp命名的函数,模块或者类会在相应的测试级别对每个用例测试前执行:

比如:

class TestSomething:

    def setUp(self):
        pass

setUp函数会在类TestSomething的每个测试函数执行前执行。

相应的,tearDown命名的函数,模块或者类会在相应的测试级别对每个用例测试后执行。

nose官方原文:

nose supports fixtures (setup and teardown methods) at the package, module, class, and test level. As with py.test or unittest fixtures, setup always runs before any test (or collection of tests for test packages and modules); teardown runs if setup has completed successfully, regardless of the status of the test run.


Support:mkdwiki