如何为邮递员测试设置 Jenkins 管道 [英] How to setup a Jenkins pipeline for postman tests

查看:20
本文介绍了如何为邮递员测试设置 Jenkins 管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Postman 被用作 API 测试的流行测试工具,您可以使用 Postman 编写大量单元测试并将它们作为构建过程的一部分执行以执行单元测试.下面介绍了 Postman 测试的 Jenkins 集成.

Postman is used as a popular testing tool for API testing, you can write bunch of unit tests using Postman and execute them as a part of your build process to perform unit testing. The following covers the Jenkins integration of Postman tests.

为了做到这一点,你应该有

In order to do that you should have

  1. 将 Postman 测试作为集合导出
  2. 在执行测试时使 API 在运行时可用.(使用 docker 或创建单独的构建管道.)

推荐答案

节点模块 newman 可用于执行 Postman 集合.请参阅以下 Package.json 文件.这里我们使用 newman 在 unit_tests 文件夹中执行 postman 集合,还定义了 newman 依赖项.

Node module newman can be used to execute Postman collections. Refer the following Package.json file. Here we are executing the postman collection inside the unit_tests folder using newman, also newman dependency is defined.

package.json

package.json

{
  "name": "postman-newman-jenkins",
  "version": "1.0.0",
  "description": "My Test Project",
  "directories": {
    "tests": "tests"
  },
  "scripts": {
    "newman-tests": "newman run unit_tests/my-collection.postman_collection.json --reporters cli,junit --reporter-junit-export newman.xml --insecure"
  },
  "author": "Test Author",
  "dependencies": {
    "newman": "^3.5.2"
  }
}

以下是Jenkinsfile的内容.我们正在使用 NPM 安装依赖项并执行测试.

The following is the content of the Jenkinsfile. We are using NPM to install the dependencies and execute tests.

詹金斯文件

pipeline {
    agent { label 'LinuxSlave' }
    stages {
        stage ('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Test'){
            steps {
                sh 'npm install'
                sh 'npm run newman-tests'
                junit 'newman.xml'
            }
        }
    }
}

这篇关于如何为邮递员测试设置 Jenkins 管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆