代码之家  ›  专栏  ›  技术社区  ›  Upul Doluweera

如何为postman测试设置Jenkins管道

  •  3
  • Upul Doluweera  · 技术社区  · 7 年前

    Postman是一种流行的API测试工具,您可以使用Postman编写一系列单元测试,并将其作为构建过程的一部分执行,以执行单元测试。下面介绍了Jenkins集成Postman测试。

    为了做到这一点,你应该

    1. 将邮递员测试导出为集合
    2. 在执行测试时,使API在运行时可用。(使用docker或创建单独的构建管道。)
    2 回复  |  直到 7 年前
        1
  •  6
  •   Upul Doluweera    7 年前

    节点模块newman可用于执行Postman集合。请参阅以下程序包。json文件。这里,我们正在 unit\u测试 文件夹使用newman,还定义了newman依赖关系。

    包裹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'
                }
            }
        }
    }
    
        2
  •  2
  •   Nir Tal    6 年前

    您可以避免在机器上安装newman(从/主)并使用 码头工人

    管道脚本示例:

    pipeline {
     agent any stages {
      stage('Test') {
       steps {
        sh 'docker run -t postman/newman_ubuntu1404 run https://www.getpostman.com/collections/8a0c9bc08f062d12dcda'
       }
      }
     }
    }
    

    有关docker的更多信息;纽曼 here