总结了接口测试unittest在使用中注意的事项

##主要是记录一下自己看。。。。。
总结了接口测试unittest在使用中注意的事项:
1)setUp(self)和TearDown(self)中只需要写一次,但是每执行一次test_case,都要执行一次:
class TestUnittest11(unittest.TestCase):
def setUp(self):
print(“初始化”)
def test_case1(self):
print(“test_case1”)
def test_case2(self):
print(“test_case2”)
def tearDown(self):
print(“销毁”)
if name == ‘main’:
unittest.main()
2)初始化的升级版setUpClass(cls)和tearDownClass(cls),只需要写一次,且整个类中也执行一次,但是需要加上装饰器@classmethod
class TestUnittest22(unittest.TestCase):
@classmethod
def setUpClass(cls) :
print(“初始化”)
def test_case1(self):
print(“test_case1”)
def test_case2(self):
print(“test_case2”)
@classmethod
def tearDownClass(cls):
print(“销毁”)
3)在main文件中引入其他文件other.py中的类OtherClass,例如:other.py中有OtherClass类
class OtherClass:
def other1(self):
print(“other1”)
def other2(self):
print(“other2”)
主文件test_Main.py需要引入OtherClass类的函数other1
首先:from xxx.sss.other import OtherClass
其次:
classTestMain(unittest.TestCase):
def test_case1(self):
OtherClass.other1(self): # 引入OtherClass类的函数other1
4) 也可以在main文件中引入其他文件other.py中的类setUp(),例如:other.py中有setUp类,使用方法可以和引入函数一样,但是在只能在main文件中的setUp()中引入一个其他类的setUp(),如果想引入多个文件的setUp(),需要将每个文件的setUp()和函数封装在一起,再进行引用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值