You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Newman生成的Postman报告中排除测试数据准备请求?

解决Newman报告仅保留待测试API请求的方法

以下是几种实用方案,可根据你的场景选择:

方案一:利用标签过滤报告内容

  1. 在Postman中给所有待测试API请求添加统一标签(比如test-target)
  2. 修改Newman命令,给htmlextra报告添加过滤参数,只显示带指定标签的请求:
newman run {collectionURL} --folder {folderName} -e {environmentURL} -d {jsonDataFile} --reporters cli,json,htmlextra --reporter-json-export {jsonReport} --reporter-htmlextra-export {htmlReport} --reporter-htmlextra-filter "tags.includes('test-target')"

该方法会执行所有请求(包括数据准备),但最终HTML报告仅展示带目标标签的请求记录。

方案二:标记数据准备请求为跳过并隐藏

  1. 在所有数据准备请求的Tests脚本中添加跳过标记:
pm.test.skip("数据准备请求", function () {});
  1. 修改Newman命令,隐藏报告中的跳过请求:
newman run {collectionURL} --folder {folderName} -e {environmentURL} -d {jsonDataFile} --reporters cli,json,htmlextra --reporter-json-export {jsonReport} --reporter-htmlextra-export {htmlReport} --reporter-htmlextra-showSkipped false

执行后,数据准备请求会被标记为跳过,且不会出现在最终报告里。

方案三:拆分执行流程(分两次运行Newman)

如果数据准备和待测试API在不同文件夹,可分两次执行:

  1. 先运行数据准备文件夹,导出执行后的环境变量(确保测试数据生效):
newman run {collectionURL} --folder "数据准备文件夹" -e {environmentURL} -d {jsonDataFile} --reporters cli --export-environment temp-env.json
  1. 再运行待测试API文件夹,使用上一步导出的环境变量并生成报告:
newman run {collectionURL} --folder "待测试API文件夹" -e temp-env.json -d {jsonDataFile} --reporters cli,json,htmlextra --reporter-json-export {jsonReport} --reporter-htmlextra-export {htmlReport}

这种方式报告里只会包含待测试API的请求记录,适合数据准备和测试逻辑完全分离的场景。

内容的提问来源于stack exchange,提问作者Asanke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 08:55:16