Enhanced JUnit XML Generator for XCTests and Swift Testing #2837
+881
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enhanced JUnit XML Generator for iOS/macOS Tests
Overview
This PR introduces a new post-action tool that generates properly formatted JUnit XML output from iOS and macOS test runs. This enhancement addresses the need for better CI/CD integration by ensuring test results are captured in a standardized format that CI systems can parse and display.
Problem Statement
When running iOS/macOS unit tests with Bazel, the default test output doesn't always produce proper JUnit XML format that CI systems expect. This makes it difficult to:
Solution
This PR adds a Python-based post-action script that:
Key Features
🎯 Dual Format Support
The parser handles both traditional XCTest output:
🚀 Performance Optimized
🧹 Clean Failure Messages
Automatically removes verbose paths from error messages:
🔧 Three Usage Options
Option 1: Pre-configured Test Runners (Easiest)
Option 2: Add to Existing Runner
Implementation Details
Components Added
tools/test_xml_generator/generate_test_xml.py- Core Python script that parses logs and generates XMLtools/test_xml_generator/test_runners.bzl- Pre-configured test runners with XML generation enabledtools/test_xml_generator/BUILD- Bazel build definitions for the Python binarytools/test_xml_generator/README.md- Comprehensive documentationHow It Works
Environment Variables
The post-action script uses these environment variables (automatically set by the test runner):
TEST_LOG_FILE- Path to the test log fileXML_OUTPUT_FILE- Path where JUnit XML should be writtenTEST_EXIT_CODE- Exit code from the test runTEST_XCRESULT_BUNDLE_PATH- Optional path to XCResult bundleSIMULATOR_UDID- Optional simulator IDExample Output
Benefits
✅ Better CI Integration - Standard JUnit XML format works with all major CI systems
✅ Improved Debugging - Clear failure messages with file locations and error details
✅ Test Trend Analysis - CI dashboards can track test success rates over time
✅ Flaky Test Detection - Better visibility into intermittent failures
✅ Zero Impact on Test Results - Post-action failures don't affect test outcomes
✅ Backward Compatible - Optional feature, doesn't change existing test behavior
✅ Performance Optimized - Minimal overhead, fast parsing and XML generation
Testing
The tool has been tested with:
Performance Impact
Migration Guide
For existing projects:
bazel-testlogs/path/to/test/test.xmlafter running testsDocumentation
Comprehensive documentation included in:
tools/test_xml_generator/README.md- Full usage guideFuture Enhancements
Potential follow-up work:
Related Issues
This addresses the need for better test result formatting and CI integration in rules_apple.
Checklist