测试执行&测试报告
测试用例执行
我这边用的pytest测试框架,测试用例执行的常用两种方式:
- 命令方式:pytest -vs ./testcases,
执行testcases文件所有的符合命名规范的测试方法(命名规范,网上资料很多),
2、pytest.ini +命令 :pytest的主配置文件,可以改变pytest的默认行为,pytest -vs ./testcases放入配置pytest.ini 如下,命令执行时直接pytest:
[pytest]
testpaths=./testcases
addopts=-vs
指定执行测试用例
有时不想跑所有的测试用例,可以指定执行,改变 pytest执行命令即可,eg:执行某个模块 pytest -vs ./testcases/test_ad.py
测试报告
pytest-html
是 pytest自带的报告,pytest-html
命令:pytest -vs --html=./report/report.html --self-contained-html,同样也可以通过配置文件简化命令:
[pytest]
testpaths=./testcases
addopts= -vs --reruns 1 --html=report.html --self-contained-html
–reruns 1 :失败重跑1次
allure(推荐这种)
- 1、生成报告文件: pytest --alluredir ./report/allure (pytes.init配置了命令的话,直接pytest)
- 2、查看报告:allure serve report/allure
[pytest]
testpaths=./testcases
addopts= --alluredir ./report/allure
如果想使allure报告展示信息更详细,可以在用例加上allure的标签,进行描述:
add_ad_data = read_excel_to_case("资源位管理", 'test_add', 6)
# print(add_ad_data)
@allure.epic("功能:后台资源位管理自动化用例,编写人:李玮;编写时间:20211105,")
@allure.feature("资源位管理测试用例")
@allure.story("新增资源位")
@allure.title("添加资源位-成功")
@allure.severity("blocker ")
@pytest.mark.parametrize("advertName,start_time,end_time,route_value,sort_value,pic_path", add_ad_data)
def test_add_ad_success(login, advertName, start_time, end_time, route_value, sort_value,
pic_path): # login 是fixture,后面参数时方法本身的参数
"""资源位添加成功"""
# driver = SelectBrowser.open_brower("firefox")
# t = Login(driver)
# t.manage_login("admin", "admin")
ad = ADPostMangeger(login)
sleep(5)
ad_text = ad.add_ad(advertName, start_time, end_time, route_value, str(sort_value), pic_path)
assert ad_text == advertName
报告截图如下: