我想用两个不同的设置和拆卸方法在同一个类中用两个不同的测试来创建unittest测试。在
每个测试将在pythonunittest框架中使用其特定的setUp和tearDown方法。在
有人能帮我吗。在
class processtestCase(unittest.TestCase):
print "start the process test cases "
def setUp1(self):
unittest.TestCase.setUp(self)
def test_test1(self):
"test Functinality"
def tearDown1(self):
unittest.TestCase.tearDown(self)
def setUp2(self):
unittest.TestCase.setUp2(self)
def test_test2(self):
"test Functinality"
def tearDown2(self):
unittest.TestCase.tearDown2(self) '
if __name__ == '__main__':
unittest.main()
在问题中,您提到您有两个测试,每个测试都有自己的设置和拆卸。至少有两种方法可供选择:
您可以将
setUp
和tearDown
代码嵌入到每个测试中:或者,可以将类拆分为两个类:
^{pr2}$第一个选项有更少的类,更短,更直。第二个选项将fixture的设置和清理以及测试代码本身更清晰地分离开来。它也证明了增加更多的测试。在
你应该根据你的具体情况和你的个人喜好来判断利弊。在
相关问题 更多 >
编程相关推荐