zoukankan      html  css  js  c++  java
  • allure为测试用例添加描述(allure.description)

      allure支持往测试报告中对测试用例添加非常详细的描述语用来描述测试用例详情,这对阅读测试报告的人来说非常的友好,可以清晰的知道每个测试用例的详情。

    allure添加描述的三种方式:

    • 使用装饰器@allure.description,传递一个字符串参数用来描述测试用例;
    • 使用装饰器@allure.description_html,传递一段HTML文本,这将在测试报告的"Description"部分渲染出来;
    • 直接在测试用例方法中通过编写文档注释的方式来添加描述;

    举个栗子:

    # file_name: test_description.py
    
    
    import pytest
    import allure
    
    
    @allure.description("""
    多行描述语:
    这是通过传递字符串参数的方式添加的一段描述语,
    使用的是装饰器@allure.description
    """)
    def test_description_provide_string():
        assert True
    
    
    @allure.description_html("""
    <h1>Test with some complicated html description</h1>
    <table style="100%" border="1">
      <tr>
        <th>Name</th>
        <th>Age</th>
        <th>Sex</th>
      </tr>
      <tr align="center">
        <td>lwjnicole</td>
        <td>28</td>
        <td>男</td>
      </tr>
      <tr align="center">
        <td>nicole</td>
        <td>29</td>
        <td>女</td>
      </tr>
    </table>
    """)
    def test_description_privide_html():
        assert True
    
    
    def test_description_docstring():
        """
        这是通过文本注释的方式添加的描述语
    
        同样支持多行描述
    
        大家好,我是lwjnicole
        :return:
        """
        assert True
    
    
    if __name__ == '__main__':
        pytest.main(['-s', 'test_description.py'])

    执行命令:

    > pytest test_description.py --alluredir=./report/result_data
    
    > allure serve ./report/result_data

    查看测试报告展示效果:

      上面的测试报告是通过装饰器@allure.description传递字符串参数来添加描述语的方式。

      上面的测试报告是通过装饰器@allure.description_html传递一段HTML文本来添加描述语的方式,这段HTML会渲染在报告的"Description"部分。

      上面的测试报告是通过直接在测试用例方法中编写文档注释来添加描述语的方式。

    allure动态更新描述语(allure.dynamic.description):

    # file_name: test_description.py
    
    
    import pytest
    import allure
    
    
    @allure.description("这是更新前的描述语,在使用allure.dynamic.description后将会被更新成新的描述语")
    def test_dynamic_description():
        assert True
        allure.dynamic.description("这是通过使用allure.dynamic.description更新后的描述语")
    
    
    if __name__ == '__main__':
        pytest.main(['-s', 'test_description.py'])

    执行命令:

    > pytest test_description.py --alluredir=./report/result_data
    
    > allure serve ./report/result_data

    查看测试报告展示效果:

      从上面的测试报告中可以看到,Description中展示的是使用allure.dynamic.description更新后的描述语。

  • 相关阅读:
    事务数据oracle 锁1
    编译文件系统移植linux3.0.62 + busybox最小系统到单板TQ2440
    事务说明[tomcat] spring2.5.6 + hiberante3.1.3 + atomikos3.8.0 多数据源事务配置
    字符判断字母顺序问题
    维度字段缓慢渐变维度的处理方式
    nullnull提取汉字第一个字母
    期望连续2013百度之星4.27月赛 题目一 Fir
    覆盖距离AsiaHatyai2012 & LA 6144 Radiation 二分搜索
    冒泡,插入,希尔,快排的比较
    链表打印从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/lwjnicole/p/14472371.html
Copyright © 2011-2022 走看看