1. 程式人生 > 實用技巧 >Maven專案分析剔除無用jar引用的方法步驟

Maven專案分析剔除無用jar引用的方法步驟

一、前言

  • @allure.title@allure.description 都是裝飾器,給測試用例提供標題和描述
  • 其實 allure 還提供了在測試用例執行過程中動態指定標題和描述等標籤的方法
  • 如: allure.dynamic.description allure.dynamic.title

二、allure.dynamic 的原始碼

class Dynamic(object):

    @staticmethod
    def title(test_title):
        plugin_manager.hook.add_title(test_title=test_title)

    @staticmethod
    def description(test_description):
        plugin_manager.hook.add_description(test_description=test_description)

    @staticmethod
    def description_html(test_description_html):
        plugin_manager.hook.add_description_html(test_description_html=test_description_html)

    @staticmethod
    def label(label_type, *labels):
        plugin_manager.hook.add_label(label_type=label_type, labels=labels)

    @staticmethod
    def severity(severity_level):
        Dynamic.label(LabelType.SEVERITY, severity_level)

    @staticmethod
    def feature(*features):
        Dynamic.label(LabelType.FEATURE, *features)

    @staticmethod
    def story(*stories):
        Dynamic.label(LabelType.STORY, *stories)

    @staticmethod
    def tag(*tags):
        Dynamic.label(LabelType.TAG, *tags)

    @staticmethod
    def link(url, link_type=LinkType.LINK, name=None):
        plugin_manager.hook.add_link(url=url, link_type=link_type, name=name)

    @staticmethod
    def issue(url, name=None):
        Dynamic.link(url, link_type=LinkType.ISSUE, name=name)

    @staticmethod
    def testcase(url, name=None):
        Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name)

重點

上面有的方法都能進行動態修改,如:

allure.dynamic.feature
allure.dynamic.link
allure.dynamic.issue
allure.dynamic.testcase
allure.dynamic.story
allure.dynamic.title
allure.dynamic.description

三、title 的例子

3.1 測試程式碼

@allure.title("裝飾器標題")
def test_1():
    print(123)
    allure.dynamic.title("動態標題")

allure 報告

四、description 的例子

4.1 測試程式碼

def test_1():
    """
    動態設定描述
    """
    print(123)
    allure.dynamic.description("動態描述")
    allure.dynamic.title("動態標題")

allure

可以看到動態描述會覆蓋動態設定描述

五、結合 parametrize

5.1 測試程式碼

data = [
    ("name1", "123456", "name1 登入成功"),
    ("name2", "123456", "name2 登入失敗"),
    ("name3", "123456", "name3 登入成功")
]


@pytest.mark.parametrize('username,pwd,title', data)
def test_2(username, pwd, title):
    """
    登入測試用例1
    """
    print(username, pwd)
    allure.dynamic.title(title)

allure 報告

六、其他屬性的例子

6.1 測試程式碼

def test_2():
    allure.dynamic.feature('動態feature')
    allure.dynamic.story('動態story')
    allure.dynamic.link("https://www.cnblogs.com/poloyy/p/1.html", '動態Link')
    allure.dynamic.issue("https://www.cnblogs.com/poloyy/p/2.html", '動態Issue')
    allure.dynamic.testcase("https://www.cnblogs.com/poloyy/p/3.html", '動態testcase')

allure報告