unittest 的一种单元测试框架,是 Python官方维护 自带的,兼容性比价好测试框架类似, 但是pytest框架使用起来更简洁,效率更高。 首先把unittest编写用例方法流程罗列 # ---------------------unittest编写用例---------------------------------------- # 用例文件:test开头 # 用例类:继承unittest.TestCase # 用例方法:test开头 # 用例只能使用类去定义 # import unittest # class TestLogin(unittest.TestCase): # # def test_01(self): # assert 1 == 100 # # def test_02(self): # assert 100 == 100 # # def test_03(self): # assert 100 == 100
pyest编写用例 罗列
# ---------------------pyest编写用例----------------------------------------
"""
# 默认的用例规范
1、用例文件:test开头
2、以test开头的函数会当成一条测试用例
3、以Test开头的类,会当成测试用例类
测试类中,以test开头的方法,会当成一条用例
# 注意点:用例规范可以自己通过pytest.ini去配置
"""
新增
# ---------------------pyest用例的前后置---------------------------------------
"""
测试类的前后置方法
1、用例级别的:setup 和teardown
2、测试类级别的前后置方法:setup_class 和teardown_class
"""import pytest
pytest.main(['-s','-v'])class TestLogin:
@classmethod
def setup_class(cls):
print('----------类级别前置---------------')
# 用例的前置方法
@classmethod
def teardown_class(cls): # tearDownClass
print('----------类级别后置---------------')
def setup(self): # setUp
print('----------用例级别前置---------------')
# 用例的前置方法
def teardown(self): # tearDown
print('----------用例级别后置---------------')
def test_c01(self):
print('------case01-------------')
assert 1000 == 1000
def test_c03(self):
print('------case02-------------')
assert 1000 == 1000
版权声明:本文为mayibangbang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。