junit2json-rs
junit2json-rs is a tool to convert JUnit XML format to JSON. From a library perspective, it provides a function to serialize Junit XML to Struct.
junit2json-rs is a reimplementation of ts-junit2json that is my previous work in TypeScript.
Purpose
junit2json-rs is designed for uploading test result data to BigQuery or any other DB that supports JSON.
Many languages and test frameworks support to output test result data as JUnit XML format, which is de fact standard in today. On the other hand, most DBs do not support to import XML but support JSON.
For this purpose, junit2json-rs provides a simple JUnit XML to JSON converter.
Install
cargo install junit2json
Usage
junit2json -p <junit_xml_file>
Output example
With jq examples
Show testsuites test count
junit2json <junit_xml_file> | jq .testsuites.tests
Show testsuite names
junit2json <junit_xml_file> | jq .testsuites.testsuite[].name
Show testcase classnames
junit2json <junit_xml_file> | jq .testsuites.testsuite[].testcase[].classname
Notice
[!IMPORTANT] junit2json-rs has some major changes from ts-junit2json. Most of the changes are to compliant with the JUnit XML Schema.
- A
testsuitesortestsuitekey appears in the root of JSON. propertieshaspropertyarray. ts-junit2json haspropertyarray of object directly.skipped,error,failureare object, not array of object.- If XML has undefined tag, it will be ignored. ts-junit2json will be converted to JSON if possible.
Referenced JUnit XML Schema:
CLI Options
A tool convert JUnit XML format to JSON with Rust
Usage: junit2json [OPTIONS] <PATH>
Arguments:
<PATH> JUnit XML path
Options:
-p, --pretty Output pretty JSON
-f, --filter-tags <FILTER_TAGS> Filter XML tag names [possible values: system-out, system-err]
-h, --help Print help
-V, --version Print version
WASI
junit2json-rs also provides WASI executable.
If you have wasm runtime (ex. wasmtime), you can execute junit2json.wasm that can download from GitHub Releases instead of native binary.
wasmtime --dir=. junit2json.wasm -- -p <junit_xml_file>
Verify attestation
We addd attestations to released binary. So everyone can verify binary attestations using gh attestation verify.
Example commands for verify artifact that released v0.2.10
Development
Setup
You can use DevContainer or Codespaces. Please see devcontainer.json.
Build
Build native binary
Build WASI
Test
# Run test
# Update snapshot
## Need to install cargo-insta first.
## `cargo install cargo-insta`
License
MIT