Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README.md #2

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 51 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,87 @@
# DBXCResultParser-Sonar

`DBXCResultParser-Sonar` is a Swift Package Manager tool designed to convert Xcode's test result files (`.xcresult`) into Sonar Generic Test Execution Report format (`.xml`). It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud.
The `DBXCResultParser-Sonar` package provides a Swift module for parsing `.xcresult` files generated by Xcode to produce [Sonar Generic Test Execution Report](https://docs.sonarsource.com/sonarqube/9.8/analyzing-source-code/test-coverage/generic-test-data/#generic-test-execution) `.xml`. It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud.

## Installation

### As a Dependency

To use `DBXCResultParser-Sonar` as a dependency in your project, add it to the dependencies in your `Package.swift` file:

```swift
dependencies: [
.package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar.git", from: "1.0.0")
]
```

Then import `DBXCResultParser-Sonar` in your Swift files where you want to use it:

```swift
import DBXCResultParserSonar
```
## Usage

### As a Command Line Tool

You can use `DBXCResultParser-Sonar` as a command line tool in two ways:

1. **Prebuilt Binary from Xcode Archive**:
Download the prebuilt binary from the [Releases](https://github.com/dodobrands/DBXCResultParser-Sonar/releases) page on the project's GitHub repository.
1. Clone repo
2. Open in Xcode
3. Product → Archive
4. Distribute Content → Built Products
5. Run exported binary:
```bash
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder>
```

2. **Using Swift Run**:

Clone the repository and run the tool using the Swift Package Manager:

```bash
git clone https://github.com/dodobrands/DBXCResultParser-Sonar.git
cd DBXCResultParser-Sonar
swift run DBXCResultParser-Sonar <arguments>
swift run DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder>
```

#### Saving .xml report to file

You can save report in two ways:

1. **Using `>` operator**:

Append `>` at the end of any bash command to redirect it's output into file.
```bash
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> > sonar-test-report.xml
```

2. **Using `--output-path` option**:

Specify option for resulting file. May be useful when you've provided `--verbode` flag so that it's logs won't conflict with output `.xml`.
```bash
./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> --output-path <path to resulting report.xml>
```

## Usage

### As a Dependency

Create an instance of `SonarGenericTestExecutionReportFormatter` and use it to generate the `.xml` report:
To use `DBXCResultParser-Sonar` in your Swift package, add it to the dependencies for your `Package.swift` file:

```swift
let formatter = SonarGenericTestExecutionReportFormatter()
// Use formatter to generate the report
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"]
)
]
)
```

### As a Command Line Tool
To parse an `.xcresult` file and access the report data, initialize a `DBXCReportModel` with the path to the `.xcresult` file:

To generate a Sonar Generic Test Execution Report from the command line, use the following command:
```swift
import DBXCResultParser_Sonar

```bash
swift run DBXCResultParser-Sonar --xcresult-path path/to/tests.xcresult --tests-path path/to/test-files > report.xml
let xcresultPath = URL(fileURLWithPath: "/path/to/your.xcresult")
let reportModel = try DBXCReportModel(xcresultPath: xcresultPath)
let formatter = SonarGenericTestExecutionReportFormatter()
let result = try formatter.sonarTestReport(from: reportModel)
```

Replace `path/to/tests.xcresult` with the path to your `.xcresult` file and `path/to/test-files` with the path to your test files.

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on the [GitHub repository](https://github.com/dodobrands/DBXCResultParser-Sonar).

## License

This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details.
```
This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details.