Allure2 报告中添加用例描述
简介
Allure 支持往测试报告中对测试用例添加非常详细的描述语,用来描述测试用例详情。
这样测试报告中会显示更多的上下文信息,帮助测试人员和开发人员更好地理解测试的目的和内容。
Allure 添加描述
@allure.description()
:为测试用例添加详细的描述信息,可以在报告中看到该描述内容。@allure.description_html()
:使用 HTML 格式化的描述内容,使描述更加丰富和可读。- 方法的文档注释
allure.dynamic.description('最终的描述信息')
:动态改变描述信息
添加装饰器 @allure.description()
@allure.description(
"""#在allure注释里的描述如果要换行展示的话要加换行符。
多行描述语:<br/>
这是通过传递字符串参数的方式添加的一段描述语,<br/>
使用的是装饰器 @allure.description
""")
def test_description_provide_string():
assert True
添加装饰器 @allure.description_html()
@allure.description_html("""html代码块""")
def test_description_privide_html():
assert True
直接在代码中添加文档注释
def test_description_docstring():
"""
#文档信息放在方法里面,会按照给定的格式展示,不需要额外的换行符‘<br/>’
直接在测试用例方法中 <br/>
通过编写文档注释的方法 <br/>
来添加描述。 <br/>
:return:
"""
assert True
代码中添加动态描述信息
import allure
@allure.description("""这个描述将被替换""")
def test_dynamic_description():
assert 42 == int(6 * 7)
allure.dynamic.description('这是最终的描述信息')
总结
- Allure 添加用例描述简介。
- Allure 添加用例描述的方式。