HTTPRunner 3 用户手册 (5) 测试报告

HTTPrunner 集成了 pytest,所以 HTTPrunner v3.x 可以使用 pytest 的所有插件,包括测试报告插件,例如pytest-htmlalluer-pytest

HTML 测试报告

HTTPrunner 安装之后自带 pytest-html插件,当你想生成 HTML 测试报告时,可以添加命令参数--html

$ hrun /path/to/testcase --html=report.html

--html=report.html中的report.html是测试报告的存放路径,没有带文件夹的时候会存放在命令运行的文件夹。

通过--html生成的 HTML 报告包含了多个文件夹,如果你要创建一个单独的 HTML 文件,可以天剑另一个命令参数--self-contained-html

$ hrun /path/to/testcase --html=report.html --self-contained-html

你可以参考pytest-html,获取更多关于 pytest-html 测试报告的信息。

allure report

pytest 支持大名鼎鼎的 allure 测试报告,HTTPrunner 集成了 pytest,也天然支持 allure。

不过 HTTPrunner 默认并未安装 allure,你需要另外安装。

安装有两种方式:

  • 安装 allure 的 pytest 依赖库 allure-pytest
  • 安装 HTTPrunner 的 allure 依赖库 httprunner[allure]

安装 allure-pytest:

$ pip3 install "allure-pytest"

安装 httprunner[allure] (推荐)

pip3 install "httprunner[allure]"

一旦 allure-pytest 准备好,以下参数就可以与 hrun/pytest 命令一起使用:

--alluredir=DIR: 生成 allure 报告到指定目录
--clean-alluredir: 如果指定目录已存在则清理该文件夹
--allure-no-capture:不要将 pytest 捕获的日志记录(logging)、标准输出(stdout)、标准错误(stderr)附加到报告中

要使 Allure 侦听器能够在测试执行期间收集结果,只需添加--alluredir选项,并提供指向存储结果的文件夹路径。如:

$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results

/tmp/my_allure_results 只会存储收集的测试结果(你将会看到一堆莫名其妙的文件,这些都是收集的测试结果),并非完成的报告,还需要通过命令生成。

要在测试完成后查看实际报告,您需要使用Allure命令行实用程序从结果中生成报告。

$ allure serve /tmp/my_allure_results

此命令将在默认浏览器中显示你生成的报告。

同时你也可以在 Jenkins 中安装 allure 报告插件,将结果与 Jenkins 集成。

你可以在 allure-pytest 查看关于 allure 报告的更多信息。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章