### CI/CD Integration Examples for JUnitReport Source: https://context7.com/topdesk/dart-junitreport/llms.txt Configuration examples for integrating JUnitReport with GitHub Actions, GitLab CI, and Jenkins. These snippets show how to activate the tool, run tests, and publish the generated JUnit XML reports. ```yaml # GitHub Actions workflow name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 - run: dart pub get - run: dart pub global activate junitreport - run: dart test --reporter json | tojunit > test-results.xml - uses: dorny/test-reporter@v1 if: always() with: name: Dart Tests path: test-results.xml reporter: java-junit --- # GitLab CI configuration test: stage: test script: - dart pub get - dart pub global activate junitreport - dart test --reporter json | tojunit > report.xml artifacts: reports: junit: report.xml --- # Jenkins Pipeline pipeline { agent any stages { stage('Test') { steps { sh 'dart pub get' sh 'dart pub global activate junitreport' sh 'dart test --reporter json | tojunit > test-results.xml' } post { always { junit 'test-results.xml' } } } } } ``` -------------------------------- ### Install and Use JUnitReport CLI Tool Source: https://context7.com/topdesk/dart-junitreport/llms.txt Demonstrates how to install the JUnitReport package globally and use the 'tojunit' command-line tool for converting JSON test results to JUnit XML format. It covers piping output directly, using input/output files, and short-form arguments. ```bash # Install the package globally dart pub global activate junitreport # Basic usage: pipe test output directly to tojunit dart test --reporter json | tojunit > TEST-report.xml # Flutter test conversion flutter test --machine | tojunit > TEST-report.xml # Using input and output files dart test --reporter json > results.jsonl tojunit --input results.jsonl --output TEST-report.xml # Short form arguments tojunit -i results.jsonl -o TEST-report.xml # View all available options tojunit --help # Output: # --input, -i the path to the 'json' file containing the output of 'pub run test'. # if missing, will be used # --output, -o the path of the to be generated junit xml file. # if missing, will be used # --base, -b the part to strip from the 'path' elements in the source # --package, -p the part to prepend to the 'path' elements in the source # --timestamp, -t the timestamp to be used in the report # --help, -h display this help text ``` -------------------------------- ### JUnit XML Output Format Example Source: https://context7.com/topdesk/dart-junitreport/llms.txt An example of the generated JUnit XML output format. This structure includes testsuites, testsuite, and testcase elements, with detailed information on test status (failures, errors, skipped) and system output. ```xml package:test_api expect test/auth_test.dart 25:5 main.<fn> Session ID: abc123 Clearing session... Skip: Not implemented yet test/auth_test.dart 45:5 main.<fn> ``` -------------------------------- ### Example JUnit XML Report Output Source: https://github.com/topdesk/dart-junitreport/blob/main/README.md An example of the JUnit XML report generated by the `tojunit` tool from Dart test results. This format is widely compatible with CI/CD systems for reporting test outcomes. ```XML ``` -------------------------------- ### Example Dart Test File Source: https://github.com/topdesk/dart-junitreport/blob/main/README.md A simple Dart test file demonstrating a basic test case using the `test` package. This file can be used with the `dart test` command to generate JSON output for conversion to JUnit XML. ```Dart import 'package:test/test.dart'; main() { test('simple', () { expect(true, true); }); } ``` -------------------------------- ### Generate JUnit Report from JSONL File (Shell) Source: https://github.com/topdesk/dart-junitreport/blob/main/example/example.md This snippet demonstrates generating a JUnit XML report by first capturing Dart test results in a JSON Lines file and then processing that file with the `tojunit` command. It requires the `junitreport` package to be installed globally. ```Shell dart test simple_test.dart --reporter json > example.jsonl dart pub global run junitreport:tojunit --input example.jsonl --output TEST-report.xml ``` -------------------------------- ### Convert Flutter Test Results to JUnit XML (Shell) Source: https://github.com/topdesk/dart-junitreport/blob/main/README.md This command executes all Flutter tests using the machine-readable output format and pipes the results directly to the `tojunit` tool for conversion into a JUnit XML report. Ensure the `junitreport` package is installed globally. -------------------------------- ### Customize JUnit XML Classname with Base and Package Options Source: https://context7.com/topdesk/dart-junitreport/llms.txt Explains how to use the `--base` and `--package` options with the `tojunit` CLI tool to customize the `classname` attribute in the generated JUnit XML report. It shows how stripping a base path and prepending a package name affects the output. ```bash # Given test file at: /home/user/myproject/test/unit/auth_test.dart # Strip the base path and add package prefix tojunit --base /home/user/myproject/test --package com.mycompany.myproject -i results.jsonl -o TEST-report.xml # Result: classname="com.mycompany.myproject.unit.auth" # Without options: classname="/home/user/myproject/test/unit/auth" # Strip only the base path tojunit -b /home/user/myproject/test -i results.jsonl -o TEST-report.xml # Result: classname="unit.auth" ``` -------------------------------- ### Stream Processing Dart Test Results to JUnit XML Source: https://context7.com/topdesk/dart-junitreport/llms.txt This Dart code snippet demonstrates how to process test output as a stream, convert it to JUnit XML format, and write it to standard output. It's useful for handling large test suites or real-time conversion during test execution. Dependencies include 'dart:convert', 'dart:io', 'package:junitreport/junitreport.dart', and 'package:testreport/testreport.dart'. ```dart import 'dart:convert'; import 'dart:io'; import 'package:junitreport/junitreport.dart'; import 'package:testreport/testreport.dart'; Future main() async { // Create processor with custom timestamp final processor = Processor(timestamp: DateTime.now()); // Process stdin as a stream (useful for piped input) await stdin .transform(utf8.decoder) .transform(const LineSplitter()) .where((line) => line.startsWith('{')) .map((line) => json.decode(line) as Map) .forEach(processor.process); // Generate report final report = processor.report; final xml = JUnitReport().toXml(report); // Output to stdout stdout.write(xml); } // Run with: dart test --reporter json | dart run my_converter.dart > TEST-report.xml ``` -------------------------------- ### Generate JUnit Report via Pipe (Shell) Source: https://github.com/topdesk/dart-junitreport/blob/main/example/example.md This snippet shows a more streamlined approach to generating a JUnit XML report by piping the JSON output of Dart tests directly to the `tojunit` command. This method is efficient for immediate report generation and requires the `junitreport` package to be globally activated. ```Shell dart test simple_test.dart --reporter json | tojunit > TEST-report.xml ``` -------------------------------- ### Programmatic JUnitReport XML Generation in Dart Source: https://context7.com/topdesk/dart-junitreport/llms.txt Shows how to use the `JUnitReport` class from the `junitreport` package in Dart to programmatically convert test results into JUnit XML format. It includes reading JSON output, processing it into a `Report` object, and generating the XML string. ```dart import 'dart:convert'; import 'dart:io'; import 'package:junitreport/junitreport.dart'; import 'package:testreport/testreport.dart'; Future main() async { // Read JSON test output from a file final file = File('test-results.jsonl'); final lines = file.readAsLinesSync(); // Process JSON lines into a Report object final processor = Processor(timestamp: DateTime.now()); for (final line in lines) { if (line.startsWith('{')) { processor.process(json.decode(line) as Map); } } final report = processor.report; // Create JUnitReport with optional base and package parameters final junitReport = JUnitReport( base: 'test/', // Strip 'test/' from paths package: 'com.example', // Prepend package name to classnames ); // Generate XML string final xml = junitReport.toXml(report); // Write to file File('TEST-report.xml').writeAsStringSync(xml); print('Generated JUnit XML report'); } ``` -------------------------------- ### Control JUnit XML Timestamp with CLI Options Source: https://context7.com/topdesk/dart-junitreport/llms.txt Details how to control the timestamp in the JUnit XML report using the `--timestamp` option in the `tojunit` CLI tool. It covers using 'now', 'none', specific ISO 8601 dates, and the default behavior when the option is omitted. ```bash # Use current date/time tojunit --timestamp now -i results.jsonl -o TEST-report.xml # Suppress timestamp entirely tojunit --timestamp none -i results.jsonl -o TEST-report.xml # Use specific UTC timestamp (ISO 8601 format) tojunit --timestamp 2024-01-15T10:30:00 -i results.jsonl -o TEST-report.xml # Default behavior (no --timestamp flag): # - If using --input file: uses file modification date # - If using stdin: uses current date/time dart test --reporter json | tojunit > TEST-report.xml # Uses current time tojunit -i results.jsonl -o TEST-report.xml # Uses results.jsonl modification time ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.