Unittest断言(六)

Zhhh 科技频道评论90字数 2090阅读6分58秒阅读模式

定义和作用:自动化测试中如期结果与实际结果的对比

基本的断言方法提供了测试结果是True还是False。所有的断言方法都有一个msg参数,如果指定msg参数的值,则将该信息作为失败的错误信息返回。文章源自玩技e族-https://www.playezu.com/26285.html

Unittest断言(六)文章源自玩技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
注意:本文法律责任由该作者承担,侵权请联系2523030730▷诈骗举报◁▷新闻不符◁▷我要投稿◁
  • 我们QQ群
  • QQ扫一扫
  • weinxin
  • 微信公众号
  • 公众号扫一扫
  • weinxin
匿名

发表评论

匿名网友

确定