unittest执行脚本的几个方法(python+selenium)

时间:2018-01-17 00:41:10   收藏:0   阅读:1445

最近搭建框架的教程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)

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!