Skip to content

Allure2报告中添加用例描述

Allure2 报告中添加用例描述

简介

Allure 支持往测试报告中对测试用例添加非常详细的描述语,用来描述测试用例详情。

Allure 添加描述的四种方式

  • 方式一:添加装饰器@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.dynamic.description_html(''' html 代码块 ''')
    

总结

  • Allure添加用例描述简介
  • Allure添加用例描述的四种方式