对于Java,有外部报告生成工具,如extent-report,testNG。 Junit为单个要素文件生成xml格式输出。为了获得详细的报告,我在Behave框架中没有看到选项或广泛的方法或解决方案。
如何在Behave中生成报告,是否需要为Behave中的报告生成添加任何其他工具或框架?
因为我使用行为的自动化都在Jenkins上运行所以我可以使用Jenkins插件来显示我的junit报告。
我认为这个问题可能会对你有所帮助:How can I generate an HTML report for Junit results?
您可以使用行为中的junit结果,并遵循此问题中的一些最佳答案。
顺便说一句,如果你想使用jenkins,如果你需要'好看的'html行为报告,我会建议你为你做行为生成json输出并使用黄瓜的记者显示json输出。
您可以为Behave测试生成Allure report。
首先,您需要安装Allure Behave格式化程序:
$ pip install allure-behave
然后在运行测试时指定格式化程序:
$ behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features
这将生成到%allure_result_folder%
的JSON报告。然后,要查看HTML报告,您可以使用Allure命令行(Jenkins / TeamCity / Bamboo的插件也可用)
$ allure serve %allure_result_folder%
有关Allure报告的更多详细信息,您可以看到docs。
Behave还可以生成jUnit XML格式的报告。只需在命令行[1]中添加--junit即可启用此功能。有关格式化程序和记者的更多信息,请参见[2]。
$ behave --junit
[1] http://pythonhosted.org/behave/behave.html?highlight=#cmdoption--junit
我知道这个问题很久以前就被提出/回答了。
但我想给出适合我的解决方案。
黄瓜json架构与Behave架构不同。所以你不能使用由行为创建的json来使用Cucumber Reports插件生成html报告。当我尝试用黄瓜报告表现json时,这就是我得到的,你也会看到NPE为uri,因为黄瓜json期望有uri存在但行为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来将行为json转换成黄瓜json。
pip install behave2cucumber
然后有一个额外的步骤,如下所示。
python -m behave2cucumber -i behave_json.json -o cucumber_json.json
-i表示由behave生成的案例json文件中的输入文件
-o表示我们的案例黄瓜兼容的json文件中的输出文件
cucumber_json.json会填充uri字段,缺少行为json。
它就像魅力一样。
希望能帮助到你。