如何在 Behave-Python 中生成报告?

新手上路,请多包涵

对于 Java,有外部报告生成工具,如 extent-report、testNG。 Junit 为单个特征文件生成 xml 格式的输出。要获得详细报告,我没有在 Behave 框架内看到一个选项或广泛的方法或解决方案。

Behave 中如何生成报表,Behave 中的报表生成是否需要添加其他工具或框架?

原文由 Ashok kumar Ganesan 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
2 个回答

您可以为您的 Behave 测试生成 Allure 报告

首先你需要安装 Allure Behave 格式化程序:

 $ pip install allure-behave

然后在运行测试时指定格式化程序:

 $ behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features

这将生成 JSON 报告到 %allure_result_folder% 。然后,要查看 HTML 报告,您可以使用 Allure 命令行(Jenkins/TeamCity/Bamboo 的插件也可用)

 $ allure serve %allure_result_folder%

有关 Allure 报告的更多详细信息,您可以查看 文档

原文由 thistle 发布,翻译遵循 CC BY-SA 3.0 许可协议

我知道这个问题很久以前就被问过/回答过。

但我想过提供对我有用的解决方案。

Cucumber json 架构不同于 Behave 架构。所以你不能使用由 behave 创建的 json 来使用 Cucumber Reports 插件生成 html 报告。当我尝试使用黄瓜报告进行 behave json 时,这就是我得到的,您还会看到 uri 的 NPE,因为 cucumber json 期望 uri 存在,但 behave json 没有 uri,因此 NPE。

 `[CucumberReport] Processing 1 json files:
 [CucumberReport] /var/lib/jenkins/jobs/behave-test/builds/14/cucumber-html-
                  reports/.cache/results.json
 [CucumberReport] Missing report result - report was not successfully completed
 [CucumberReport] Build status is left unchanged`

您会看到报告未成功完成。

所以我安装了 behave2cucumber 来将 behave json 转换成 cucumber json。

pip install behave2cucumber

然后像下面这样进行额外的步骤。

python -m behave2cucumber -i behave_json.json -o cucumber_json.json

-i 在我们的案例中代表输入文件 json 文件由 behave 生成

-o 在我们的案例中代表黄瓜兼容 json 文件中的输出文件

cucumber_json.json 将填充缺少 behave json 的 uri 字段。

它就像魅力一样。

希望能帮助到你。

原文由 Thayz 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题