小编典典

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

jenkins

Postman用作API测试的流行测试工具,您可以使用Postman编写一堆单元测试,并将其作为构建过程的一部分执行以执行单元测试。以下内容涵盖了Postman测试的Jenkins集成。

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

  1. 导出的邮递员测试作为集合
  2. 执行测试时,请在运行时使API可用。(使用docker或通过创建单独的构建管道。)

阅读 247

收藏
2020-07-25

共1个答案

小编典典

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

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安装依赖项并执行测试。

詹金斯档案

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