最近搭建框架的教程http://blog.csdn.net/u011541946/article/category/6788788
addTest
可以加载不同类里面的不同测试函数
# coding = utf-8 import unittest import testsuites from testsuites.test_baidu_search import BaiduSearch from testsuites.test_get_page_title import GetPageTitle suite = unittest.TestSuite() suite.addTest(BaiduSearch(‘test_baidu_search‘)) suite.addTest(BaiduSearch(‘test_search2‘)) suite.addTest(GetPageTitle(‘test_get_title‘)) if __name__==‘__main__‘: #执行用例 runner=unittest.TextTestRunner() runner.run(suite)
makeSuit()
一次性加载一个类文件下所有的测试用例到suite中去
# coding = utf-8 import unittest import testsuites from testsuites.test_baidu_search import BaiduSearch from testsuites.test_get_page_title import GetPageTitle suite = unittest.TestSuite(unittest.makeSuite(BaiduSearch)) if __name__==‘__main__‘: #执行用例 runner=unittest.TextTestRunner() runner.run(suite)
discover()
跑testsuite包下的所有测试用例
可以在discover中直接传入包名或者文件夹名称
# coding = utf-8 import unittest suite = unittest.TestLoader().discover("testsuites") if __name__==‘__main__‘: #执行用例 runner=unittest.TextTestRunner() runner.run(suite)