DBXCResultParser-Sonar

DBXCResultParser-Sonar 包提供了一个 Swift 模块,用于解析 Xcode 生成的 .xcresult 文件,以生成 Sonar 通用测试执行报告 .xml 文件。 它可以集成到您的 CI/CD 管道中,以增强 SonarQube 或 SonarCloud 中测试结果的可视性。

使用方法

作为命令行工具

您可以通过两种方式使用 DBXCResultParser-Sonar 作为命令行工具

  1. 来自 Xcode 归档的预构建二进制文件:

    1. 克隆仓库
    2. 在 Xcode 中打开
    3. Product → Archive(产品 → 归档)
    4. Distribute Content → Built Products(分发内容 → 构建产品)
    5. 运行导出的二进制文件
    ./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder>
  2. 使用 Swift Run:

    克隆存储库并使用 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>

将 .xml 报告保存到文件

您可以通过两种方式保存报告

  1. 使用 > 运算符:

    在任何 bash 命令的末尾添加 >,以将其输出重定向到文件中。

    ./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> > sonar-test-report.xml
  2. 使用 --output-path 选项:

    指定结果文件的选项。当您提供 --verbode 标志时,这可能很有用,这样它的日志就不会与输出的 .xml 文件冲突。

    ./DBXCResultParser-Sonar --xcresult-path <path> --tests-path <your projects tests folder> --output-path <path to resulting report.xml>

作为依赖项

要在您的 Swift 包中使用 DBXCResultParser-Sonar,请将其添加到您的 Package.swift 文件的依赖项中

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"]
        )
    ]
)

要解析 .xcresult 文件并访问报告数据,请使用 .xcresult 文件的路径初始化 DBXCReportModel

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)

贡献

欢迎贡献!请随时提交 pull request 或在 GitHub 存储库上打开 issue。

许可证

此项目根据 Apache License 获得许可 - 有关详细信息,请参阅 LICENSE 文件。