{"id":34,"date":"2026-05-28T10:00:00","date_gmt":"2026-05-28T02:00:00","guid":{"rendered":"http:\/\/localhost:8888\/?p=34"},"modified":"2026-07-09T16:17:45","modified_gmt":"2026-07-09T08:17:45","slug":"postman%e9%ab%98%e7%ba%a7%e6%8a%80%e5%b7%a7%e6%8f%ad%e7%a7%98","status":"publish","type":"post","link":"https:\/\/blog.runnergo.cn\/?p=34","title":{"rendered":"Postman\u9ad8\u7ea7\u6280\u5de7\u63ed\u79d8 &#8211; \u4ece\u63a5\u53e3\u6d4b\u8bd5\u5230\u81ea\u52a8\u5316Mock\u670d\u52a1\u642d\u5efa"},"content":{"rendered":"<h1>Postman\u9ad8\u7ea7\u6280\u5de7\u63ed\u79d8 - \u4ece\u63a5\u53e3\u6d4b\u8bd5\u5230\u81ea\u52a8\u5316Mock\u670d\u52a1\u642d\u5efa<\/h1>\n\n&gt; \u4f5c\u8005\uff1aQA\u653b\u57ce\u72ee\n---\n\n<h2>\u524d\u8a00<\/h2>\n\n\u5927\u5bb6\u597d\uff0c\u6211\u662fQA\u653b\u57ce\u72ee\uff0c\u505a\u63a5\u53e3\u6d4b\u8bd56\u5e74\u4e86\u3002Postman\u662f\u6211\u6700\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5f88\u591a\u6d4b\u8bd5\u540c\u884c\u7528\u5b83\u53d1\u8bf7\u6c42\u3001\u770b\u54cd\u5e94\uff0c\u4f46\u8fd9\u53ea\u662fPostman\u7684\u57fa\u7840\u529f\u80fd\u3002\u4eca\u5929\u5206\u4eab\u4e00\u4e9bPostman\u7684\u9ad8\u7ea7\u6280\u5de7\uff0c\u8ba9\u4f60\u7684\u63a5\u53e3\u6d4b\u8bd5\u66f4\u4e13\u4e1a\u3002\n\n\u8fd9\u7bc7\u6587\u7ae0\u4f1a\u8986\u76d6\uff1a\n<ul><li>\u73af\u5883\u53d8\u91cf\u4e0e\u5168\u5c40\u53d8\u91cf\u7ba1\u7406<\/li>\n<li>Pre-request Script\u4e0eTests Script<\/li>\n<li>Mock Server\u642d\u5efa<\/li>\n<li>Newman\u547d\u4ee4\u884c\u8fd0\u884c<\/li>\n<li>CI\/CD\u96c6\u6210<\/li>\n<li>\u56e2\u961f\u534f\u4f5c\u6700\u4f73\u5b9e\u8df5<\/li>\n<\/ul>\n---\n\n<h2>\u4e00\u3001\u53d8\u91cf\u7ba1\u7406<\/h2>\n\n<h3>\u53d8\u91cf\u7c7b\u578b<\/h3>\n\nPostman\u67095\u79cd\u53d8\u91cf\uff0c\u4f5c\u7528\u57df\u4ece\u5c0f\u5230\u5927\uff1a\n\n| \u53d8\u91cf\u7c7b\u578b | \u4f5c\u7528\u57df | \u7528\u9014 |\n|----------|--------|------|\n| Local\u53d8\u91cf | \u5355\u6b21\u8bf7\u6c42 | \u4e34\u65f6\u6570\u636e |\n| Data\u53d8\u91cf | Collection Runner | \u6279\u91cf\u6d4b\u8bd5\u6570\u636e |\n| Environment\u53d8\u91cf | \u73af\u5883 | \u73af\u5883\u914d\u7f6e |\n| Collection\u53d8\u91cf | Collection | \u5171\u4eab\u914d\u7f6e |\n| Global\u53d8\u91cf | \u5168\u5c40 | \u8de8\u73af\u5883\u6570\u636e |\n\n<h3>\u73af\u5883\u53d8\u91cf<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\npm.environment.set(\"base_url\", \"https:\/\/api.test.com\");\npm.environment.set(\"token\", \"Bearer abc123\");\n\n\/\/ \u83b7\u53d6\u73af\u5883\u53d8\u91cf\nconst baseUrl = pm.environment.get(\"base_url\");\nconst token = pm.environment.get(\"token\");\n\n\/\/ \u5220\u9664\u73af\u5883\u53d8\u91cf\npm.environment.unset(\"token\");\n\n\/\/ \u6e05\u7a7a\u6240\u6709\u73af\u5883\u53d8\u91cf\npm.environment.clear();\n<code>`<\/code>\n\n\u5728\u8bf7\u6c42\u4e2d\u4f7f\u7528\uff1a\n<code>`<\/code>\n{{base_url}}\/users\/{{user_id}}\n<code>`<\/code>\n\n<h3>\u5168\u5c40\u53d8\u91cf<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u8bbe\u7f6e\u5168\u5c40\u53d8\u91cf\npm.globals.set(\"version\", \"v1\");\n\n\/\/ \u83b7\u53d6\u5168\u5c40\u53d8\u91cf\npm.globals.get(\"version\");\n<code>`<\/code>\n\n<h3>Collection\u53d8\u91cf<\/h3>\n\n\u5728Collection\u8bbe\u7f6e\u4e2d\u6dfb\u52a0\uff1a\n<ul><li>\u53d8\u91cf\u540d\uff1a<code>retry_count<\/code><\/li>\n<li>\u53d8\u91cf\u503c\uff1a<code>3<\/code><\/li>\n<\/ul>\n<code>`<\/code>javascript\n\/\/ \u4f7f\u7528Collection\u53d8\u91cf\nconst retry = pm.collectionVariables.get(\"retry_count\");\n<code>`<\/code>\n\n<h3>\u52a8\u6001\u53d8\u91cf<\/h3>\n\nPostman\u5185\u7f6e\u52a8\u6001\u53d8\u91cf\uff1a\n\n<code>`<\/code>\n{{$timestamp}}      \/\/ \u5f53\u524d\u65f6\u95f4\u6233\n{{$randomInt}}      \/\/ \u968f\u673a\u6574\u6570\n{{$randomEmail}}    \/\/ \u968f\u673a\u90ae\u7bb1\n{{$guid}}           \/\/ UUID\n{{$date}}           \/\/ \u5f53\u524d\u65e5\u671f\n{{$isoDate}}        \/\/ ISO\u683c\u5f0f\u65e5\u671f\n<code>`<\/code>\n\n\u793a\u4f8b\uff1a\n<code>`<\/code>json\n{\n    \"email\": \"{{$randomEmail}}\",\n    \"id\": \"{{$guid}}\",\n    \"timestamp\": \"{{$timestamp}}\"\n}\n<code>`<\/code>\n\n---\n\n<h2>\u4e8c\u3001\u811a\u672c\u7f16\u5199<\/h2>\n\n<h3>Pre-request Script\uff08\u8bf7\u6c42\u524d\u811a\u672c\uff09<\/h3>\n\n\u5728\u53d1\u9001\u8bf7\u6c42\u524d\u6267\u884c\u7684\u811a\u672c\uff0c\u7528\u4e8e\uff1a\n<ul><li>\u52a8\u6001\u751f\u6210\u8bf7\u6c42\u53c2\u6570<\/li>\n<li>\u8ba1\u7b97\u7b7e\u540d<\/li>\n<li>\u8bbe\u7f6e\u8bf7\u6c42\u5934<\/li>\n<\/ul>\n<code>`<\/code>javascript\n\/\/ Pre-request Script\u793a\u4f8b\n\n\/\/ \u751f\u6210\u65f6\u95f4\u6233\nconst timestamp = Date.now();\npm.environment.set(\"timestamp\", timestamp);\n\n\/\/ \u8ba1\u7b97\u7b7e\u540d\uff08\u793a\u4f8b\uff09\nconst secret = pm.environment.get(\"secret\");\nconst params = <code>timestamp=${timestamp}&amp;secret=${secret}<\/code>;\nconst sign = CryptoJS.MD5(params).toString();\npm.environment.set(\"sign\", sign);\n\n\/\/ \u8bbe\u7f6e\u52a8\u6001\u8bf7\u6c42\u5934\npm.request.headers.add({\n    key: \"X-Signature\",\n    value: sign\n});\n\n\/\/ \u53d1\u9001\u524d\u7f6e\u8bf7\u6c42\uff08\u83b7\u53d6Token\uff09\npm.sendRequest({\n    url: pm.environment.get(\"base_url\") + \"\/auth\/token\",\n    method: \"POST\",\n    header: {\"Content-Type\": \"application\/json\"},\n    body: {\n        mode: \"raw\",\n        raw: JSON.stringify({\n            username: \"test\",\n            password: \"test123\"\n        })\n    }\n}, function(err, res) {\n    if (!err) {\n        const token = res.json().access_token;\n        pm.environment.set(\"auth_token\", token);\n    }\n});\n<code>`<\/code>\n\n<h3>Tests Script\uff08\u6d4b\u8bd5\u811a\u672c\uff09<\/h3>\n\n\u5728\u6536\u5230\u54cd\u5e94\u540e\u6267\u884c\u7684\u811a\u672c\uff0c\u7528\u4e8e\uff1a\n<ul><li>\u9a8c\u8bc1\u54cd\u5e94\u6570\u636e<\/li>\n<li>\u63d0\u53d6\u6570\u636e\u5b58\u5165\u53d8\u91cf<\/li>\n<li>\u65ad\u8a00\u6d4b\u8bd5<\/li>\n<\/ul>\n<code>`<\/code>javascript\n\/\/ Tests Script\u793a\u4f8b\n\n\/\/ \u57fa\u7840\u65ad\u8a00\npm.test(\"\u72b6\u6001\u7801\u4e3a200\", function() {\n    pm.response.to.have.status(200);\n});\n\npm.test(\"\u54cd\u5e94\u65f6\u95f4\u5c0f\u4e8e500ms\", function() {\n    pm.expect(pm.response.responseTime).to.be.below(500);\n});\n\npm.test(\"\u54cd\u5e94\u5305\u542bdata\u5b57\u6bb5\", function() {\n    pm.response.to.have.jsonBody(\"data\");\n});\n\n\/\/ JSON\u6570\u636e\u9a8c\u8bc1\nconst jsonData = pm.response.json();\n\npm.test(\"\u7528\u6237\u5217\u8868\u4e0d\u4e3a\u7a7a\", function() {\n    pm.expect(jsonData.data.length).to.be.above(0);\n});\n\npm.test(\"\u7528\u6237ID\u4e3a\u6b63\u6574\u6570\", function() {\n    jsonData.data.forEach(user =&gt; {\n        pm.expect(user.id).to.be.a(\"number\").and.to.be.above(0);\n    });\n});\n\npm.test(\"\u54cd\u5e94\u7ed3\u6784\u6b63\u786e\", function() {\n    pm.expect(jsonData).to.have.property(\"code\");\n    pm.expect(jsonData).to.have.property(\"message\");\n    pm.expect(jsonData).to.have.property(\"data\");\n});\n\n\/\/ \u63d0\u53d6\u54cd\u5e94\u6570\u636e\nconst userId = jsonData.data[0].id;\npm.environment.set(\"user_id\", userId);\n\n\/\/ \u4fdd\u5b58\u54cd\u5e94\u5230\u6587\u4ef6\uff08Collection Runner\uff09\npm.collectionVariables.set(\"last_response\", pm.response.text());\n<code>`<\/code>\n\n<h3>\u5e38\u7528\u65ad\u8a00\u65b9\u6cd5<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u72b6\u6001\u7801\u65ad\u8a00\npm.test(\"\u72b6\u6001\u7801\u4e3a200\", () =&gt; {\n    pm.response.to.have.status(200);\n});\n\npm.test(\"\u72b6\u6001\u7801\u4e3a2xx\", () =&gt; {\n    pm.response.to.be.success;\n});\n\npm.test(\"\u72b6\u6001\u7801\u4e3a4xx\", () =&gt; {\n    pm.response.to.be.clientError;\n});\n\n\/\/ \u54cd\u5e94\u4f53\u65ad\u8a00\npm.test(\"\u54cd\u5e94\u4f53\u4e0d\u4e3a\u7a7a\", () =&gt; {\n    pm.response.to.not.be.empty;\n});\n\npm.test(\"\u54cd\u5e94\u4e3aJSON\", () =&gt; {\n    pm.response.to.be.json;\n});\n\n\/\/ JSON\u5b57\u6bb5\u65ad\u8a00\npm.test(\"\u5305\u542btoken\u5b57\u6bb5\", () =&gt; {\n    pm.response.to.have.jsonBody(\"token\");\n});\n\npm.test(\"token\u4e0d\u4e3a\u7a7a\", () =&gt; {\n    const json = pm.response.json();\n    pm.expect(json.token).to.not.be.null;\n});\n\n\/\/ \u54cd\u5e94\u5934\u65ad\u8a00\npm.test(\"\u5305\u542bContent-Type\", () =&gt; {\n    pm.response.to.have.header(\"Content-Type\");\n});\n\npm.test(\"Content-Type\u4e3aJSON\", () =&gt; {\n    pm.response.headers.get(\"Content-Type\").includes(\"application\/json\");\n});\n<code>`<\/code>\n\n---\n\n<h2>\u4e09\u3001Mock Server\u642d\u5efa<\/h2>\n\n<h3>\u4e3a\u4ec0\u4e48\u9700\u8981Mock<\/h3>\n\n\u63a5\u53e3\u6d4b\u8bd5\u573a\u666f\uff1a\n<ul><li>\u5f00\u53d1\u7684\u63a5\u53e3\u8fd8\u6ca1\u5b8c\u6210\uff0c\u65e0\u6cd5\u8c03\u7528<\/li>\n<li>\u7b2c\u4e09\u65b9\u63a5\u53e3\u4e0d\u7a33\u5b9a\uff0c\u5f71\u54cd\u6d4b\u8bd5<\/li>\n<li>\u9700\u8981\u6d4b\u8bd5\u7279\u5b9a\u54cd\u5e94\uff08\u5982\u9519\u8bef\u7801\u3001\u8fb9\u754c\u503c\uff09<\/li>\n<li>\u524d\u540e\u7aef\u5e76\u884c\u5f00\u53d1<\/li>\n<\/ul>\n<h3>\u521b\u5efaMock Server<\/h3>\n\n1. <strong>\u521b\u5efaMock Collection<\/strong>\n\n\u5728Postman\u4e2d\uff1a\n<ul><li>\u70b9\u51fb <code>Mock Server<\/code> -&gt; <code>Create Mock Server<\/code><\/li>\n<li>\u9009\u62e9Collection\u6216\u521b\u5efa\u65b0\u7684<\/li>\n<\/ul>\n2. <strong>\u5b9a\u4e49Mock\u54cd\u5e94<\/strong>\n\n\u5728\u8bf7\u6c42\u7684 <code>Examples<\/code> \u4e2d\u6dfb\u52a0\u54cd\u5e94\u793a\u4f8b\uff1a\n\n<code>`<\/code>json\n\/\/ \u6210\u529f\u54cd\u5e94\u793a\u4f8b\n{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"users\": [\n            {\"id\": 1, \"name\": \"\u5f20\u4e09\"},\n            {\"id\": 2, \"name\": \"\u674e\u56db\"}\n        ]\n    }\n}\n\n\/\/ \u9519\u8bef\u54cd\u5e94\u793a\u4f8b\n{\n    \"code\": 404,\n    \"message\": \"\u7528\u6237\u4e0d\u5b58\u5728\",\n    \"data\": null\n}\n<code>`<\/code>\n\n3. <strong>\u914d\u7f6eMock\u73af\u5883<\/strong>\n\n<code>`<\/code>javascript\n\/\/ Mock\u73af\u5883\u53d8\u91cf\n{\n    \"mock_url\": \"https:\/\/mock.postman.com\/my-mock\"\n}\n<code>`<\/code>\n\n<h3>Mock Server\u5b9e\u6218<\/h3>\n\n<code>`<\/code>javascript\n\/\/ Pre-request Script\uff1a\u6839\u636e\u573a\u666f\u9009\u62e9Mock\u54cd\u5e94\nconst testScenario = pm.environment.get(\"scenario\");\n\nif (testScenario === \"success\") {\n    pm.request.url = pm.environment.get(\"mock_url\") + \"\/success\";\n} else if (testScenario === \"error\") {\n    pm.request.url = pm.environment.get(\"mock_url\") + \"\/error\";\n}\n<code>`<\/code>\n\n<h3>Mock\u6570\u636e\u751f\u6210<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u52a8\u6001\u751f\u6210Mock\u6570\u636e\nfunction generateMockUser(id) {\n    return {\n        id: id,\n        name: <code>\u7528\u6237${id}<\/code>,\n        email: <code>user${id}@test.com<\/code>,\n        phone: <code>1380000000${id}<\/code>,\n        createTime: new Date().toISOString()\n    };\n}\n\n\/\/ Mock\u54cd\u5e94\u793a\u4f8b\nconst mockData = {\n    code: 200,\n    message: \"success\",\n    data: {\n        users: Array.from({length: 10}, (_, i) =&gt; generateMockUser(i + 1)),\n        total: 10,\n        page: 1,\n        pageSize: 10\n    }\n};\n<code>`<\/code>\n\n---\n\n<h2>\u56db\u3001Collection Runner\u6279\u91cf\u6d4b\u8bd5<\/h2>\n\n<h3>\u8fd0\u884cCollection<\/h3>\n\n\u5728Postman\u754c\u9762\uff1a\n1. \u70b9\u51fbCollection -&gt; <code>Run<\/code>\n2. \u9009\u62e9\u8981\u8fd0\u884c\u7684\u8bf7\u6c42\n3. \u8bbe\u7f6e\u8fd0\u884c\u53c2\u6570\n\n<h3>\u914d\u7f6e\u8fd0\u884c\u53c2\u6570<\/h3>\n\n<ul><li><strong>Iterations<\/strong>\uff1a\u8fed\u4ee3\u6b21\u6570<\/li>\n<li><strong>Delay<\/strong>\uff1a\u8bf7\u6c42\u95f4\u9694<\/li>\n<li><strong>Data File<\/strong>\uff1aCSV\/JSON\u6d4b\u8bd5\u6570\u636e\u6587\u4ef6<\/li>\n<\/ul>\n<h3>\u6d4b\u8bd5\u6570\u636e\u6587\u4ef6<\/h3>\n\n<strong>CSV\u683c\u5f0f\uff1a<\/strong>\n<code>`<\/code>\nusername,password,expected_status\ntestuser,password123,200\nwronguser,wrongpass,401\nemptyuser,,400\n<code>`<\/code>\n\n<strong>JSON\u683c\u5f0f\uff1a<\/strong>\n<code>`<\/code>json\n[\n    {\"username\": \"testuser\", \"password\": \"password123\", \"expected_status\": 200},\n    {\"username\": \"wronguser\", \"password\": \"wrongpass\", \"expected_status\": 401}\n]\n<code>`<\/code>\n\n<h3>\u4f7f\u7528\u6d4b\u8bd5\u6570\u636e<\/h3>\n\n<code>`<\/code>javascript\n\/\/ Tests Script\u4e2d\u4f7f\u7528\u6570\u636e\u53d8\u91cf\nconst expectedStatus = pm.iterationData.get(\"expected_status\");\n\npm.test(\"\u72b6\u6001\u7801\u9a8c\u8bc1\", function() {\n    pm.response.to.have.status(expectedStatus);\n});\n<code>`<\/code>\n\n---\n\n<h2>\u4e94\u3001Newman\u547d\u4ee4\u884c\u8fd0\u884c<\/h2>\n\n<h3>\u5b89\u88c5Newman<\/h3>\n\n<code>`<\/code>bash\nnpm install -g newman\n<code>`<\/code>\n\n<h3>\u57fa\u7840\u547d\u4ee4<\/h3>\n\n<code>`<\/code>bash\n<h1>\u8fd0\u884cCollection<\/h1>\nnewman run collection.json\n\n<h1>\u6307\u5b9a\u73af\u5883<\/h1>\nnewman run collection.json -e environment.json\n\n<h1>\u6307\u5b9a\u5168\u5c40\u53d8\u91cf<\/h1>\nnewman run collection.json -g globals.json\n\n<h1>\u4f7f\u7528\u6d4b\u8bd5\u6570\u636e<\/h1>\nnewman run collection.json -d data.csv\n\n<h1>\u8bbe\u7f6e\u8fed\u4ee3\u6b21\u6570<\/h1>\nnewman run collection.json -n 10\n\n<h1>\u6307\u5b9a\u62a5\u544a\u683c\u5f0f<\/h1>\nnewman run collection.json -r cli,json,html\n\n<h1>\u8f93\u51fa\u62a5\u544a\u6587\u4ef6<\/h1>\nnewman run collection.json -r json --reporter-json-export report.json\n<code>`<\/code>\n\n<h3>Newman\u914d\u7f6e\u6587\u4ef6<\/h3>\n\n<code>`<\/code>json\n\/\/ newman.config.json\n{\n    \"collection\": \"collection.json\",\n    \"environment\": \"environment.json\",\n    \"globals\": \"globals.json\",\n    \"iterationCount\": 5,\n    \"delay\": 500,\n    \"reporters\": [\"cli\", \"html\"],\n    \"reporter\": {\n        \"html\": {\n            \"export\": \"report.html\",\n            \"template\": \"custom-template.hbs\"\n        }\n    }\n}\n<code>`<\/code>\n\n\u8fd0\u884c\uff1a\n<code>`<\/code>bash\nnewman run newman.config.json\n<code>`<\/code>\n\n---\n\n<h2>\u516d\u3001CI\/CD\u96c6\u6210<\/h2>\n\n<h3>Jenkins\u96c6\u6210<\/h3>\n\n1. <strong>\u5b89\u88c5NodeJS\u63d2\u4ef6<\/strong>\n\n2. <strong>Pipeline\u811a\u672c<\/strong>\n\n<code>`<\/code>groovy\npipeline {\n    agent any\n\n    stages {\n        stage('\u5b89\u88c5Newman') {\n            steps {\n                sh 'npm install -g newman'\n            }\n        }\n\n        stage('\u8fd0\u884c\u63a5\u53e3\u6d4b\u8bd5') {\n            steps {\n                sh '''\n                    newman run tests\/collection.json \n                        -e tests\/environment.json \n                        -r cli,html,junit \n                        --reporter-html-export reports\/newman-report.html \n                        --reporter-junit-export reports\/newman-report.xml\n                '''\n            }\n        }\n\n        stage('\u53d1\u5e03\u62a5\u544a') {\n            steps {\n                publishHTML([\n                    reportDir: 'reports',\n                    reportFiles: 'newman-report.html',\n                    reportName: 'API Test Report'\n                ])\n            }\n        }\n    }\n\n    post {\n        always {\n            archiveArtifacts artifacts: 'reports\/*', allowEmptyArchive: true\n        }\n    }\n}\n<code>`<\/code>\n\n<h3>GitLab CI\u96c6\u6210<\/h3>\n\n<code>`<\/code>yaml\n<h1>.gitlab-ci.yml<\/h1>\nstages:\n  - test\n\napi_test:\n  stage: test\n  image: node:18\n  before_script:\n    - npm install -g newman\n  script:\n    - newman run tests\/collection.json\n        -e tests\/environment.json\n        -r cli,html\n        --reporter-html-export reports\/newman-report.html\n  artifacts:\n    paths:\n      - reports\/\n    expire_in: 1 week\n<code>`<\/code>\n\n<h3>GitHub Actions\u96c6\u6210<\/h3>\n\n<code>`<\/code>yaml\n<h1>.github\/workflows\/api-test.yml<\/h1>\nname: API Test\n\non:\n  push:\n    branches: [main]\n  pull_request:\n    branches: [main]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions\/checkout@v3\n\n      - name: Setup Node\n        uses: actions\/setup-node@v3\n        with:\n          node-version: '18'\n\n      - name: Install Newman\n        run: npm install -g newman\n\n      - name: Run API Tests\n        run: |\n          newman run tests\/collection.json \n            -e tests\/environment.json \n            -r cli,html \n            --reporter-html-export reports\/newman-report.html\n\n      - name: Upload Report\n        uses: actions\/upload-artifact@v3\n        with:\n          name: api-test-report\n          path: reports\/\n<code>`<\/code>\n\n---\n\n<h2>\u4e03\u3001\u56e2\u961f\u534f\u4f5c\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n<h3>Collection\u7ec4\u7ec7\u7ed3\u6784<\/h3>\n\n<code>`<\/code>\n\u9879\u76eeCollection\/\n\u251c\u2500\u2500 01-\u8ba4\u8bc1\u6a21\u5757\/\n\u2502   \u251c\u2500\u2500 \u767b\u5f55\n\u2502   \u251c\u2500\u2500 \u6ce8\u518c\n\u2502   \u2514\u2500\u2500 \u5237\u65b0Token\n\u251c\u2500\u2500 02-\u7528\u6237\u6a21\u5757\/\n\u2502   \u251c\u2500\u2500 \u83b7\u53d6\u7528\u6237\u5217\u8868\n\u2502   \u251c\u2500\u2500 \u83b7\u53d6\u7528\u6237\u8be6\u60c5\n\u2502   \u251c\u2500\u2500 \u521b\u5efa\u7528\u6237\n\u2502   \u251c\u2500\u2500 \u66f4\u65b0\u7528\u6237\n\u2502   \u2514\u2500\u2500 \u5220\u9664\u7528\u6237\n\u251c\u2500\u2500 03-\u8ba2\u5355\u6a21\u5757\/\n\u2502   \u251c\u2500\u2500 \u521b\u5efa\u8ba2\u5355\n\u2502   \u251c\u2500\u2500 \u67e5\u8be2\u8ba2\u5355\n\u2502   \u2514\u2500\u2500 \u53d6\u6d88\u8ba2\u5355\n\u2514\u2500\u2500 04-\u516c\u5171\u63a5\u53e3\/\n    \u251c\u2500\u2500 \u6587\u4ef6\u4e0a\u4f20\n    \u2514\u2500\u2500 \u83b7\u53d6\u914d\u7f6e\n<code>`<\/code>\n\n<h3>\u73af\u5883\u7ba1\u7406<\/h3>\n\n\u521b\u5efa\u591a\u4e2a\u73af\u5883\uff1a\n<ul><li><strong>Dev\u73af\u5883<\/strong>\uff1a\u5f00\u53d1\u73af\u5883\u6d4b\u8bd5<\/li>\n<li><strong>Test\u73af\u5883<\/strong>\uff1a\u6d4b\u8bd5\u73af\u5883<\/li>\n<li><strong>Staging\u73af\u5883<\/strong>\uff1a\u9884\u53d1\u5e03\u73af\u5883<\/li>\n<li><strong>Prod\u73af\u5883<\/strong>\uff1a\u751f\u4ea7\u73af\u5883\uff08\u53ea\u8bfb\u6d4b\u8bd5\uff09<\/li>\n<\/ul>\n<h3>\u53d8\u91cf\u547d\u540d\u89c4\u8303<\/h3>\n\n<code>`<\/code>\n\/\/ \u73af\u5883\u53d8\u91cf\uff1a\u73af\u5883\u76f8\u5173\u914d\u7f6e\n{{base_url}}\n{{api_version}}\n{{auth_token}}\n\n\/\/ Collection\u53d8\u91cf\uff1aCollection\u901a\u7528\u914d\u7f6e\n{{timeout}}\n{{retry_count}}\n\n\/\/ Global\u53d8\u91cf\uff1a\u8de8Collection\u5171\u4eab\n{{test_user}}\n{{default_headers}}\n<code>`<\/code>\n\n<h3>Pre-request Script\u6700\u4f73\u5b9e\u8df5<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u901a\u7528\u8bf7\u6c42\u5934\u8bbe\u7f6e\npm.request.headers.add({\n    key: \"Content-Type\",\n    value: \"application\/json\"\n});\n\npm.request.headers.add({\n    key: \"Accept\",\n    value: \"application\/json\"\n});\n\n\/\/ \u81ea\u52a8\u6dfb\u52a0Token\uff08\u5982\u679c\u5b58\u5728\uff09\nconst token = pm.environment.get(\"auth_token\");\nif (token) {\n    pm.request.headers.add({\n        key: \"Authorization\",\n        value: <code>Bearer ${token}<\/code>\n    });\n}\n\n\/\/ \u6dfb\u52a0\u8bf7\u6c42ID\uff08\u7528\u4e8e\u65e5\u5fd7\u8ffd\u8e2a\uff09\npm.request.headers.add({\n    key: \"X-Request-ID\",\n    value: <code>{{$guid}}<\/code>\n});\n<code>`<\/code>\n\n<h3>Tests Script\u6700\u4f73\u5b9e\u8df5<\/h3>\n\n<code>`<\/code>javascript\n\/\/ \u7edf\u4e00\u7684\u54cd\u5e94\u9a8c\u8bc1\u6a21\u677f\npm.test(\"API\u54cd\u5e94\u9a8c\u8bc1\", function() {\n    \/\/ \u72b6\u6001\u7801\u9a8c\u8bc1\n    pm.response.to.have.status(200);\n\n    \/\/ \u54cd\u5e94\u65f6\u95f4\u9a8c\u8bc1\n    pm.expect(pm.response.responseTime).to.be.below(1000);\n\n    \/\/ \u54cd\u5e94\u7ed3\u6784\u9a8c\u8bc1\n    const json = pm.response.json();\n    pm.expect(json).to.have.property(\"code\");\n    pm.expect(json).to.have.property(\"message\");\n    pm.expect(json).to.have.property(\"data\");\n\n    \/\/ \u4e1a\u52a1\u903b\u8f91\u9a8c\u8bc1\n    if (json.code === 200) {\n        pm.expect(json.message).to.equal(\"success\");\n    }\n});\n<code>`<\/code>\n\n---\n\n<h2>\u516b\u3001Postman vs RunnerGo<\/h2>\n\n\u5728\u505a\u63a5\u53e3\u6d4b\u8bd5\u65f6\uff0c\u9664\u4e86Postman\uff0cRunnerGo\u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff1a\n\n| \u529f\u80fd | Postman | RunnerGo |\n|------|---------|----------|\n| \u63a5\u53e3\u8c03\u8bd5 | \u652f\u6301 | \u652f\u6301 |\n| \u81ea\u52a8\u5316\u6d4b\u8bd5 | Newman\u547d\u4ee4\u884c | \u53ef\u89c6\u5316\u7f16\u6392 |\n| Mock Server | \u652f\u6301 | \u652f\u6301 |\n| \u6027\u80fd\u6d4b\u8bd5 | \u4e0d\u652f\u6301 | \u5185\u7f6e\u652f\u6301 |\n| \u6d4b\u8bd5\u62a5\u544a | \u9700\u63d2\u4ef6 | \u5185\u7f6e\u7f8e\u89c2\u62a5\u544a |\n| \u56e2\u961f\u534f\u4f5c | \u4ed8\u8d39 | \u4f01\u4e1a\u7248\u652f\u6301 |\n| \u4e2d\u6587\u652f\u6301 | \u90e8\u5206\u4e2d\u6587 | \u5b8c\u5168\u4e2d\u6587 |\n\nRunnerGo\u7684\u4f18\u52bf\uff1a\n<ul><li>\u96c6\u63a5\u53e3\u6d4b\u8bd5\u3001\u6027\u80fd\u6d4b\u8bd5\u3001\u81ea\u52a8\u5316\u6d4b\u8bd5\u4e8e\u4e00\u4f53<\/li>\n<li>\u53ef\u89c6\u5316\u7f16\u6392\uff0c\u4e0d\u9700\u8981\u5199\u811a\u672c<\/li>\n<li>\u5185\u7f6eMock\u670d\u52a1<\/li>\n<li>\u6027\u80fd\u6d4b\u8bd5\u529f\u80fd\u5f3a\u5927<\/li>\n<li>\u5b8c\u6574\u4e2d\u6587\u754c\u9762\u548c\u6587\u6863<\/li>\n<\/ul>\n\u540e\u7eed\u7b2c21-25\u671f\u6587\u7ae0\u4f1a\u8be6\u7ec6\u4ecb\u7ecdRunnerGo\u5b9e\u6218\u3002\n\n---\n\n<h2>\u603b\u7ed3<\/h2>\n\nPostman\u9ad8\u7ea7\u6280\u5de7\u603b\u7ed3\uff1a\n\n| \u6280\u672f\u70b9 | \u7528\u9014 |\n|--------|------|\n| \u53d8\u91cf\u7ba1\u7406 | \u73af\u5883\u914d\u7f6e\u3001\u6570\u636e\u4f20\u9012 |\n| Pre-request Script | \u52a8\u6001\u53c2\u6570\u3001\u524d\u7f6e\u5904\u7406 |\n| Tests Script | \u65ad\u8a00\u9a8c\u8bc1\u3001\u6570\u636e\u63d0\u53d6 |\n| Mock Server | \u6a21\u62df\u63a5\u53e3\u3001\u8fb9\u754c\u6d4b\u8bd5 |\n| Newman | CI\/CD\u96c6\u6210\u3001\u81ea\u52a8\u5316 |\n| Collection Runner | \u6279\u91cf\u6d4b\u8bd5\u3001\u6570\u636e\u9a71\u52a8 |\n\n\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0cPostman\u4e0d\u53ea\u662f\u63a5\u53e3\u8c03\u8bd5\u5de5\u5177\uff0c\u66f4\u662f\u5f3a\u5927\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u5e73\u53f0\u3002\n\n---\n\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n\n<ul><li>Postman\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/learning.postman.com\/<\/li>\n<li>Newman\u6587\u6863\uff1ahttps:\/\/github.com\/postmanlabs\/newman<\/li>\n<li>Postman API\u6587\u6863\uff1ahttps:\/\/docs.api.postman.com\/<\/li>\n<li>RunnerGo\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/wiki.runnergo.cn\/docs\/<\/li>\n<\/ul>\n---\n\n<strong>\u4e0b\u671f\u9884\u544a\uff1aJMeter\u5206\u5e03\u5f0f\u538b\u6d4b\u5b9e\u6218 - \u4ece\u5355\u673a\u5230\u96c6\u7fa4\u7684\u6027\u80fd\u6d4b\u8bd5\u65b9\u6848<\/strong>\n\n&gt; \u4f5c\u8005\uff1aQA\u653b\u57ce\u72ee\uff0c6\u5e74\u63a5\u53e3\u6d4b\u8bd5\u7ecf\u9a8c\uff0c\u64c5\u957fPostman\u3001RunnerGo\u7b49\u5de5\u5177\u3002\u77e5\u4e4e\uff1aQA\u653b\u57ce\u72ee","protected":false},"excerpt":{"rendered":"<p>Postman\u9ad8\u7ea7\u6280\u5de7\u63ed\u79d8 &#8211; \u4ece\u63a5\u53e3\u6d4b\u8bd5\u5230\u81ea\u52a8\u5316Mock\u670d\u52a1\u642d\u5efa &gt; \u4f5c\u8005\uff1aQA\u653b\u57ce\u72ee &#8212; \u524d\u8a00 \u5927\u5bb6\u597d\uff0c\u6211\u662fQA\u653b\u57ce\u72ee\uff0c\u505a\u63a5\u53e3\u6d4b\u8bd56\u5e74\u4e86\u3002Postman\u662f\u6211\u6700\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5f88\u591a\u6d4b\u8bd5\u540c\u884c\u7528\u5b83&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=34"}],"version-history":[{"count":0,"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.runnergo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}