本节将讲解如何在 Jenkins 中运行 Postman 中的用例。
这主要借助 Newman 的命令行运行功能。
使用 Newman 在命令行中运行:
我们先看一下示例的 collection在命令行中的运行效果:

在 Jenkins 中设置 Newman 运行
打开本地的 Jenkins 地址 http://localhost:8080
:

新建一个自由风格的构建任务:

在构建Build
栏,新建一个构建步骤, 并选择Execute shell
:
如果是 windows 上部署的 Jenkins 则选择
Execute Windows batch command

输入以下命令(windows 与 linux 上命令一致):
$ newman run "Postman Echo.postman_collection.json"
-r cli,junit,html --reporter-junit-export echo.xml --reporter-html-export echo.html
配置报告
上面的命令运行后会生成两份测试报告,junit 格式的和 html 格式的,运行后都会存放在当前任务的根目录jenkins/workspace/Jenkins_Newman_Test
中。
在 Post-bulid Actions 中添加 Publish HTML reports 用来展示 HTML 报告,添加 Publish Junit test result report 用来展示 Junit 报告:

点击保存 Save 按钮完成配置:
在任务中点击构建,可以看到构建后的界面:

网友评论