定义和作用:自动化测试中如期结果与实际结果的对比
基本的断言方法提供了测试结果是True还是False。所有的断言方法都有一个msg参数,如果指定msg参数的值,则将该信息作为失败的错误信息返回。
文章源自玩技e族-https://www.playezu.com/26285.html
Skip操作(无条件跳过):(以下代码示例继承于传参过多)文章源自玩技e族-https://www.playezu.com/26285.html
#无条件跳过本次用例 @unittest.skip('跳过本次用例的原因')
from ddt import ddt, file_data
from base.login_base import keyDemo
from time import sleep
import unittest
@ddt
class CassDemo(unittest.TestCase):
def setUp(self) -> None:
self.kd = keyDemo('Chrome')
self.kd.maxwindow()
def tearDown(self) -> None:
self.kd.quite()
@file_data('../data/search.yaml')
def test_01(self, **kwargs):
print(kwargs)
# self.kd = keyDemo('Chrome')
self.kd.open(kwargs['url'])
self.kd.input(**kwargs['input'])
self.kd.click(**kwargs['click'])
print(['url'])
sleep(3)
# self.kd.quite()
@unittest.skip('此业务停止')
def test_02(self, **kwargs):
print(kwargs)
# self.kd = keyDemo('Chrome')
self.kd.open(kwargs['url'])
self.kd.input(**kwargs['input'])
self.kd.click(**kwargs['click'])
print(['url'])
sleep(3)
# self.kd.quite()
if __name__ == '__main__':
unittest.main()
Skip操作(有条件跳过)文章源自玩技e族-https://www.playezu.com/26285.html
from ddt import ddt, file_data from base.login_base import keyDemo from time import sleep import unittest @ddt class CassDemo(unittest.TestCase): def setUp(self) -> None: self.kd = keyDemo('Chrome') self.kd.maxwindow() def tearDown(self) -> None: self.kd.quite() @file_data('../data/search.yaml') def test_01(self, **kwargs): print(kwargs) # self.kd = keyDemo('Chrome') self.kd.open(kwargs['url']) self.kd.input(**kwargs['input']) self.kd.click(**kwargs['click']) print(['url']) sleep(3) # self.kd.quite() # 无条件执行跳过用例操作 @unittest.skip('此业务停止') def test_02(self, **kwargs): print(kwargs) # self.kd = keyDemo('Chrome') self.kd.open(kwargs['url']) self.kd.input(**kwargs['input']) self.kd.click(**kwargs['click']) print(['url']) sleep(3) # self.kd.quite() # 有条件跳过本次用例操作 @unittest.skipUnless(1 > 2, '此业务停止') def test_03(self, **kwargs): print(kwargs) # self.kd = keyDemo('Chrome') self.kd.open(kwargs['url']) self.kd.input(**kwargs['input']) self.kd.click(**kwargs['click']) print(['url']) sleep(3) # self.kd.quite() # 有条件跳过本次用例操作 @unittest.skipIf(1 < 2, '此业务停止') def test_03(self, **kwargs): print(kwargs) # self.kd = keyDemo('Chrome') self.kd.open(kwargs['url']) self.kd.input(**kwargs['input']) self.kd.click(**kwargs['click']) print(['url']) sleep(3) # self.kd.quite() if __name__ == '__main__': unittest.main()文章源自玩技e族-https://www.playezu.com/26285.html文章源自玩技e族-https://www.playezu.com/26285.html
评论