python中unittest的使用
2021-05-06 07:26
标签:self res 函数 pen dsfa 目录 stc over faq python中unittest的使用 标签:self res 函数 pen dsfa 目录 stc over faq 原文地址:https://www.cnblogs.com/LinxiHuang/p/13191088.htmlimport unittest
断言的使用
class Testcase(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
pass
def tearDown(self):
pass
def test01(self):
print("01")
def test02(self):
print("02")
if __name__ == "__main__":
unittest.main()import unittest
import sys
sys.path.append("dir")添加当前工程目录
from Unittest.test_case01 import Testcase01
from Unittest.test_case01 import Testcase02
testcase01 = unittest.TestLoader().loadTestsFromTestCase(Testcase01)
testcase02 = unittest.TestLoader().loadTestsFromTestCase(Testcase02)
suote = unittest.TestCase([testcase01,testcase02])
unittest.TextTestRunner().run(suote)@unittest.skip("这个case不执行")
unittest中case的批量管理
def test_07(self):
print("执行case07")
flag = "adfadfadfadfadsfaqeewr"
s = "fads"
self.assertIn(s, flag, msg="不包含")
@unittest.skipIf(4==5,"执行")
def test_01(self):
print("执行case01")
# res = requests.get(url=url,params=data).json()
data1 = {
"user": "11111"
}
self.assertDictEqual(data1, data)import unittest
import sys
import os
sys.path.append("dir")添加当前工程目录
from Unittest.test_case01 import Testcase01
from Unittest.test_case01 import Testcase02
case_path = os.getcwd() + ‘/Unittestcase‘
discover = unittest.defaultTestLoader.discover(case_path)
unittest.TextTestRunner().run(discover)
文章标题:python中unittest的使用
文章链接:http://soscw.com/index.php/essay/83100.html