文章目录
一、 测试模块定制-feature二、测试功能定制- stroy三、测试步骤定制-step四、测试描述定制五、严重级别定制六、 Issue和TestCase定制七、附件文件的定制八、代码九、生成Allure测试报告9.1 运行收集测试结果9.2 查看测试结果官网:link
官方文档: link
报告预览
一、 测试模块定制-feature
@allure.feature("测试模块名字")
二、测试功能定制- stroy
@allure.story("用户故事名字")
三、测试步骤定制-step
@allure.step("测试步骤一")
四、测试描述定制
@allure.attach("我是测试步骤一的描述")
用例描述也可以直接注释在测试函数中
五、严重级别定制
@allure.severity("Normal")
严重级别:BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL
Allure中对严重级别的定义:
1、 Blocker级别:中断缺陷(客户端程序无响应,无法执行下一步操作)
2、 Critical级别:临界缺陷( 功能点缺失)
3、 Normal级别:普通缺陷(数值计算错误)
4、 Minor级别:次要缺陷(界面错误与UI需求不符)
5、 Trivial级别:轻微缺陷(必输项无提示,或者提示不规范)
六、 Issue和TestCase定制
@allure.issue(URL,"issue名字")@allure.testcase(URL,"testcase名字")
七、附件文件的定制
allure.attach.file(文件路径, 文件在报告中显示的名字, 文件类型)
@allure.attach.file("./test.png", "test pic in report", allure.attachment_type.PNG)
八、代码
import allureimport pytest@allure.feature("测试feature1")class TestFeatureOne:@allure.story("测试story 1")@allure.severity("Critical")@allure.testcase("", "我是测试用例的URL")@allure.issue("", "我是bug管理的URL")def test_story1_case1(self):"""story 1 case 1的用例描述:test story 1 的test case 1:return: 成功1"""allure.attach("我是用例1另外的附加描述")with allure.step("我是 story 1中test case 1 的操作步骤 1"):print("测试步骤1 打印 hello word")with allure.step("我是 story 1中test case 1 的操作步骤 2"):assert 1@allure.story("测试story 1")@allure.severity("Normal")def test_story1_case2(self):"""story 1 case 2的用例描述:test story 1 的test case 2,添加一个图片附件:return: 图片附件"""with allure.step("我是添加附件的操作步骤"):allure.attach.file("./test.png", "test pic in report", allure.attachment_type.PNG)@allure.story("测试story 2")@allure.severity("Blocker")def test_story2_case1(self):"""story 2 case 1 的用例描述:test story 2 的test case1 用来测试 fail:return: 失败1"""assert 0@allure.story("测试story 2")@allure.severity("Minor")def test_story2_case2(self):"""story 2 case 2 的用例描述:test story 2 的test case2:return: 失败2"""assert 0@allure.feature("测试feature2")class TestFeatureTwo:@allure.story("测试story 3")@allure.severity("Critical")def test_story3(self):"""story3 的用例描述:return: 成功"""assert 1@allure.story("测试story 4")@allure.severity("Normal")def test_story4(self):"""story 4 的用例描述:return: 失败"""assert 0
九、生成Allure测试报告
9.1 运行收集测试结果
命令行使用如下命令:
pytest test.py(测试文件) --alluredir= ./results
(说明:–alluredir这个选项用于指定储存测试报告结果的路径)
pytest test_allure.py --alluredir=./results
9.2 查看测试结果
方法一:在线查看测试报告,会直接打开默认浏览器展示当前报告
命令行:
allure serve ./results
方法二:从结果生产报告,这是一个启动tomcat的服务,需要两个步骤
1.生成报告命令:
allure generate ./results -o ./report --clean
(覆盖路径需要加–clean)
2.打开报告命令:
allure open -h 127.0.0.1 -p 8883 ./report