python test suit_python unittest学习3---添加测试套件,testsuit
一下例子即把testcase添加到suit里面
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual("foo".upper(), "FOO")
def test_isupper(self):
self.assertTrue("FOO".isupper())
self.assertFalse("Foo".isupper())
def test_split(self):
s="hello world"
self.assertEqual(s.split(),["hello","world"])
def suite():
suite=unittest.TestSuite()
suite.addTest(TestStringMethods("test_upper"))
suite.addTest(TestStringMethods("test_isupper"))
return suite
if __name__=="__main__":
runner=unittest.TextTestRunner()
runner.run(suite())
此時運行時,就會跑test_upper,test_isupper
備注:添加的測試用例必須是按照基礎類TestCase創建出來的測試用例,如果只是單個方法,添加時會報錯
總結
以上是生活随笔為你收集整理的python test suit_python unittest学习3---添加测试套件,testsuit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql5.7 archive安装_对
- 下一篇: java 销毁线程_线程 学习教程(一)