一个命令行工具和一组库,可将 Dart 测试的 JSON 输出转换为 JUnit XML 格式,非常适合用于 CI/CD 集成。它还提供了结构化的模型,以开发者友好的方式解析测试结果。专为使用 Flutter 或 Dart 项目的团队设计,可在 Android、iOS、Web、macOS、Windows 和 Linux 等平台上实现标准化的测试报告。该包简化了测试结果分析,并增强了自动化流水线中的可见性。
适合场景
CI/CD 测试报告
与 Jenkins 或 GitHub Actions 集成
生成标准化测试报告
以编程方式解析测试结果
跨平台测试验证
提高测试结果的可读性
主要特点
将测试 JSON 转换为 JUnit XML
提供开发者友好的测试结果模型
支持多个平台
轻松集成 CLI
可扩展的解析工具
干净、结构化的输出
适合对象
使用 Flutter 和 Dart 的团队
CI/CD 流水线开发者
测试自动化工程师
需要 JUnit 兼容性的项目
需要结构化测试数据的开发人员
使用建议
需要 Dart 测试 JSON 输入
需要在 CI 工作流中进行设置
仅限测试报告使用场景
不支持实时测试
依赖外部测试框架的输出
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
better_test_reporter
Introduction
This is an application/library heavily inspired by
dart-junitreport and
dart-testreport. It takes what was
done in those two packages and brings them under a single umbrella, updates to
null-safety, and makes various code style improvements.
The purpose of this package is three-fold:
Firstly, it provides models by which output from the test json
reporter
can be decoded.
Secondly, it provides a processor that will take a full json
report from the test json reporter and generate a more developer-friendly report
model structure that is agnostic to the protocol version of the test json
reporter.
Thirdly, it is a command-line application(report_to_junit) that
can be used to take in a full json report from the test json reporter and
generate a junit XML report(usable by many CI tools)
Experimental nature
This package is still experimental as we continue to build out more functionality. It's current state is barebones as we investigate ways to make the junit output more useful and ways to produce better testing reports for use outside of just junit.
Getting Started
In order to start using the report_to_junit command, install the latest
better_test_reporter as a global package via pub.dev.
pub global activate better_test_reporter
Options
Details on all options for report_to_junit can be found by running report_to_junit --help
> report_to_junit --help
-i, --input the path to the 'json' file containing the output of 'pub run test'.
if missing, <stdin> will be used
-o, --output the path of the to be generated junit xml file.
if missing, <stdout> will be used
-b, --base the part to strip from the 'path' elements in the source
(defaults to the current working directory)
-p, --package the part to prepend to the 'path' elements in the source
(defaults to "")
-t, --timestamp the timestamp to be used in the report
- 'now' will use the current date/time
- 'none' will suppress timestamps altogether
- a date formatted 'yyyy-MM-ddThh:mm:ss' will be used as UTC date/time
- if no value is provided
- if'--input' is specified the file modification date/time is used
- otherwise the current date/time is used
-h, --help display this help text
Misc
Differences from original implementation in dart-junitreport and dart-testreport
When generating the XML for a problem during a test, dart-junitreport had a
special case for only one problem occurred. The multiple problem case also
handled the case for a single problem. We found the special case for a single
problem unneeded and a little buggy, so it was removed in
better_test_reporter.
When parsing the test reporter json into a report,
dart-testreport set tests as not hidden if they encountered any problems while
running. In better_test_reporter, the hidden attribute on a test will be
purely based on whether the test was explicitly hidden based on the
TestDoneEvent json. That said, we maintained the hidden behavior for the
output junit xml by shifting that decision out of the report and up to whatever
consumes the report.
When generating the XML for a test case, better_test_reporter defaults to
stripping the current working directory out of the classname.