Postman 被用作 API 测试的流行测试工具,您可以使用 Postman 编写大量单元测试并将它们作为构建过程的一部分执行以执行单元测试。下面介绍了 Postman 测试的 Jenkins 集成。
为了做到这一点,你应该有
节点模块 newman 可用于执行 Postman 集合。请参阅以下 Package.json 文件。在这里,我们使用 newman执行unit_tests文件夹中的postman集合,还定义了 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"
}
}
Run Code Online (Sandbox Code Playgroud)
以下是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'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6411 次 |
最近记录: |