俗話說「人靠衣服馬靠鞍」一個項目作的在好,沒有一分的漂亮的測試報告有時候也是很難在客戶那邊驗收的,今天宏哥就帶大家解決這一難題。html
前邊一篇文章是分享如何搭建pytest+Allure的環境,從而生成一份精美的、讓人耳目一新的測試報告,可是有的小夥伴或者童鞋們可能會問,我能不能按照本身的想法爲個人項目測試結果量身打造一份屬於我本身的測試報告了,固然能夠了。函數
Allure提供瞭如下經常使用註解(未列出部分請訪問官網瞭解),具體用法以下。學習
Feature: 標註主要功能模塊
Story: 標註Features功能模塊下的分支功能
Severity: 標註測試用例的重要級別
Step: 標註測試用例的重要步驟
Issue和TestCase: 標註Issue、Case,可加入URL測試
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-30 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.feature('test_module_01') def test_case_01(): """ 用例描述:Test case 01 """ assert 0 @allure.feature('test_module_02') def test_case_02(): """ 用例描述:Test case 02 """ assert 0 == 0 if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.feature('test_module_01') @allure.story('test_story_01') def test_case_01(): """ 用例描述:Test case 01 """ assert 0 @allure.feature('test_module_02') @allure.story('test_story_02') def test_case_02(): """ 用例描述:Test case 02 """ assert 0 == 0 if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.feature('test_module_01') @allure.story('test_story_01') #test_case_01爲用例title def test_case_01(): """ 用例描述:這是用例描述,Test case 01,描述本人 """ #註釋爲用例描述 assert 0 if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
Allure中對嚴重級別的定義:
一、 Blocker級別:中斷缺陷(客戶端程序無響應,沒法執行下一步操做)
二、 Critical級別:臨界缺陷( 功能點缺失)
三、 Normal級別:普通缺陷(數值計算錯誤)
四、 Minor級別:次要缺陷(界面錯誤與UI需求不符)
五、 Trivial級別:輕微缺陷(必輸項無提示,或者提示不規範)編碼
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.feature('test_module_01') @allure.story('test_story_01') @allure.severity('blocker') def test_case_01(): """ 用例描述:Test case 01 """ assert 0 @allure.feature('test_module_01') @allure.story('test_story_01') @allure.severity('critical') def test_case_02(): """ 用例描述:Test case 02 """ assert 0 == 0 @allure.feature('test_module_01') @allure.story('test_story_02') @allure.severity('normal') def test_case_03(): """ 用例描述:Test case 03 """ assert 0 @allure.feature('test_module_01') @allure.story('test_story_02') @allure.severity('minor') def test_case_04(): """ 用例描述:Test case 04 """ assert 0 == 0 if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.step("字符串相加:{0},{1}") # 測試步驟,可經過format機制自動獲取函數參數 def str_add(str1, str2): if not isinstance(str1, str): return "%s is not a string" % str1 if not isinstance(str2, str): return "%s is not a string" % str2 return str1 + str2 @allure.feature('test_module_01') @allure.story('test_story_01') @allure.severity('blocker') def test_case(): str1 = 'hello' str2 = '宏哥' assert str_add(str1, str2) == 'hello宏哥' if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest @allure.step("字符串相加:{0},{1}") # 測試步驟,可經過format機制自動獲取函數參數 def str_add(str1, str2): print('hello') if not isinstance(str1, str): return "%s is not a string" % str1 if not isinstance(str2, str): return "%s is not a string" % str2 return str1 + str2 @allure.feature('test_module_01') @allure.story('test_story_01') @allure.severity('blocker') @allure.issue("http://www.baidu.com") @allure.testcase("http://www.testlink.com") def test_case(): str1 = 'hello' str2 = '宏哥' assert str_add(str1, str2) == 'hello宏哥' if __name__ == '__main__': pytest.main(['-s', '-q', '--alluredir', './report'])
# coding=utf-8 # 1.先設置編碼,utf-8可支持中英文,如上,通常放在第一行 # 2.註釋:包括記錄建立時間,建立人,項目名稱。 ''' Created on 2019-9-29 @author: 北京-宏哥 QQ交流羣:707699217 Project:手把手教你Pytest+Allure2.X定製報告詳細教程,給本身的項目量身打造一套測試報告 ''' # 3.導入模塊 import allure import pytest # file = open('C:\\Users\\DELL\\Desktop\\duhong\\test.png', 'rb').read() # allure.attach('test_img', file, allure.attachment_type.PNG)PNG @pytest.fixture def attach_file_in_module_scope_fixture_with_finalizer(request): allure.attach('A text attacment in module scope fixture', 'blah blah blah', allure.attachment_type.TEXT) def finalizer_module_scope_fixture(): allure.attach('A text attacment in module scope finalizer', 'blah blah blah blah', allure.attachment_type.TEXT) request.addfinalizer(finalizer_module_scope_fixture) def test_with_attacments_in_fixture_and_finalizer(attach_file_in_module_scope_finalizer): pass def test_multiple_attachments(): allure.attach.file('C:\\Users\\DELL\\Desktop\\duhong\\test.png', attachment_type=allure.attachment_type.PNG) allure.attach('<head></head><body> a page </body>', 'Attach with HTML type', allure.attachment_type.HTML)
此外,Allure還支持Jenkins Plugin,後面我會專門寫一篇博文給小夥伴們繼續介紹和分享,感興趣的話請關注個人博客。spa
其實上面說的你們均可以到官網來學習allure的用法和使用。code
好了,明天就是國慶節了,宏哥這裏提早祝你們國慶節快樂,吃好玩好喝好。orm
您的確定就是我進步的動力。若是你感受還不錯,就請鼓勵一下吧!記得點波 推薦 哦!!!(點擊右邊的小球便可!(^__^) 嘻嘻……)htm
原文出處:https://www.cnblogs.com/du-hong/p/11607926.htmlblog