⚠️ Notice: This formatter has been integrated into Peekie (formerly DBXCResultParser) asSonarFormatter. We recommend using Peekie instead of this repository for new projects and migrating existing projects to Peekie. Peekie provides the same SonarQube formatter functionality along with additional features, better maintenance, and active development.
The DBXCResultParser-Sonar package provides a Swift module for parsing .xcresult files generated by Xcode to produce Sonar Generic Test Execution Report .xml. It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud.
For new projects, please use Peekie which includes SonarFormatter with the same functionality.
You can use DBXCResultParser-Sonar as a command line tool in two ways:
-
Prebuilt Binary from Xcode Archive:
- Clone repo
- Open in Xcode
- Product → Archive
- Distribute Content → Built Products
- Run exported binary:
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder>
-
Using Swift Run:
Clone the repository and run the tool using the Swift Package Manager:
git clone https://github.com/dodobrands/DBXCResultParser-Sonar.git cd DBXCResultParser-Sonar swift run DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder>
You can save report in two ways:
-
Using
>operator:Append
>at the end of any bash command to redirect it's output into file../DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> > sonar-test-report.xml
-
Using
--output-pathoption:Specify option for resulting file. May be useful when you've provided
--verbodeflag so that it's logs won't conflict with output.xml../DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> --output-path <path to resulting report.xml>
To use DBXCResultParser-Sonar in your Swift package, add it to the dependencies for your Package.swift file:
let package = Package(
name: "YourPackageName",
dependencies: [
.package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar", .upToNextMajor(from: "1.0.0"))
],
targets: [
.target(
name: "YourTargetName",
dependencies: ["DBXCResultParser"]
)
]
)To parse an .xcresult file and access the report data, initialize a DBXCReportModel with the path to the .xcresult file:
import DBXCResultParser_Sonar
let xcresultPath = URL(fileURLWithPath: "/path/to/your.xcresult")
let reportModel = try DBXCReportModel(xcresultPath: xcresultPath)
let formatter = SonarGenericTestExecutionReportFormatter()
let result = try formatter.sonarTestReport(from: reportModel)Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
This project is licensed under the Apache License - see the LICENSE file for details.