HTML報告展示
1. 需要HTML Publisher plugin插件
2. 在workspace下的工程(構建)中的目錄中存儲測試報告
在Jenkins中新建一個job,進入配置項。
首先通過pytest生成測試報告

注,py.test執行測試后生成報告,會生成在workspace的當前project目錄中,例如C:\Program Files (x86)\Jenkins\workspace\test_html_report\reports\report.html
配置報告展示
1) 選擇構建后操作步驟 > Publish HTML reports

2) 配置路徑,注意路徑是相對於workspace的項目開始,例如當前項目名字為test_html_report,生成的報告存放的位置為
C:\Program Files (x86)\Jenkins\workspace\test_html_report\reports\report.html
。那么配置如下:

3)配置好后,執行構建。構建完成后,就可以在項目頁面看到配置的HTML報告

點擊進去就可以看到報告的內容:

XML報告展示
XML報告是Jenkins自帶的Junit測試報告展示,不用下載任何插件
同樣以上面的py test例子,開始配置
1) 同樣增加構建后的步驟 > Publish Junit test result report

- 同樣注意路徑

3)配置完成后,可以在構建頁面看到測試報告了。注意,是構建頁面,不是項目頁面。HTML報告是展示在項目頁面,而xml報告展示在構建頁面。


就可以看到測試報告了。

附上:test_add.py中隨手寫的示例測試代碼(注意,需要pip intsall pytest)
def add(a, b): return a + b def test_str(): ''' 測試字符串 :return: ''' # 測試失敗 assert add('1', '2') == '112' def test_int(): ''' 測試整型 :return: ''' assert add(1, 2) == 3 class TestAdd(): def test_list(self): assert add([1], [2]) == [1,2] def test_tuple(self): assert add((1,), (2,)) == (1,2)