如何为邮递员测试设置 Jenkins 管道邮递员、何为、管道、测试

2023-09-07 10:56:43 作者:犀利的眼神◆猥琐的表情

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

将 Postman 测试作为集合导出在执行测试时使 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'
            }
        }
    }
}
 
精彩推荐
图片推荐