Allure2 添加用例分类

Allure2 添加用例分类

  • 应用场景:可以为项目,以及项目下的不同模块对用例进行分类管理。也可以运行某个类别下的用例。

  • 报告展示:类别会展示在测试报告的 Behaviors 栏目下。

  • Allure提供了三个装饰器:
    1、@allure.epic:敏捷里面的概念,定义史诗,往下是feature;

    适用场景:希望在测试报告中看到用例所在的项目,需要用到 epic,相当于定义一个项目的需求,由于粒度比较大,
    在 epic 下面还要定义略小粒度的用户故事。

import allure

@allure.epic("需求1")
class TestEpic:
    def test_case1(self):
        print("用例1")

    def test_case2(self):
        print("用例2")

    def test_case3(self):
        print("用例3")

2、@allure.feature/story:功能点的描述,理解成模块,往下是story,故事story是feature的子集;;
适用场景:希望在报告中看到测试功能,子功能或场景。

import allure

@allure.epic("需求1")
@allure.feature("功能模块1")
class TestEpic:
    @allure.story("子功能1")
    @allure.title("用例1")
    def test_case1(self):
        print("用例1")

    @allure.story("子功能2")
    @allure.title("用例2")
    def test_case2(self):
        print("用例2")

    @allure.story("子功能2")
    @allure.title("用例3")
    def test_case3(self):
        print("用例3")

    @allure.story("子功能1")
    @allure.title("用例4")
    def test_case4(self):
        print("用例4")

3、allure 相关的命令查看 :
pytest --help|grep allure
通过指定命令行参数,运行 epic/feature/story 相关的用例:
pytest 文件名 --allure-epics=EPICS_SET --allure-features=FEATURES_SET --allure-stories=STORIES_SET

# 只运行 epic 名为 "需求1" 的测试用例
pytest --alluredir ./results --clean-alluredir --allure-epics=需求1

# 只运行 feature 名为 "功能模块2" 的测试用例
pytest --alluredir ./results --clean-alluredir --allure-features=功能模块2

# 只运行 story 名为 "子功能1" 的测试用例
pytest --alluredir ./results --clean-alluredir --allure-stories=子功能1

# 运行 story 名为 "子功能1和子功能2" 的测试用例
pytest --alluredir ./results --clean-alluredir --allure-stories=子功能1,子功能2

# 运行 feature + story 的用例(取并集)
pytest --alluredir ./results --clean-alluredir --allure-features=功能模块1 --allure-stories=子功能1,子功能2
Allure epic/feature/story 的关系
  • Allure epic/feature/story 的关系
    epic:敏捷里面的概念,用来定义史诗,相当于定义一个项目。
    feature:相当于一个功能模块,相当于 testsuite,可以管理很多个子分支 story。
    story:相当于对应这个功能或者模块下的不同场景,分支功能。
    epic 与 feature、feature 与 story 类似于父子关系。