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

查看:85
本文介绍了如何为邮递员测试设置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.

为此,您应该拥有


  1. 导出为集合的Postman测试

  2. 在执行测试时在运行时使API可用。 (使用docker或创建单独的构建管道。)


推荐答案

节点模块newman可以是用于执行邮递员收藏。请参考以下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.


Jenkinsfile

Jenkinsfile



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天全站免登陆