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)
网友评论