Swift 测试报告生成器

CI

一个 Swift 库,用于创建 JUnit XML 测试结果,可以被 Bamboo 或 Jenkins 等工具解析。

示例输出

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite tests="2" failures="0" disabled="0" errors="0" time="0.0013051033020019531" name="JUnitReporterTests">
    <testcase classname="SwiftTestReporterTests.JUnitReporterTests" name="testReporterShouldReturnXMLForEmptySuite" time="0.0007890462875366211"></testcase>
    <testcase classname="SwiftTestReporterTests.JUnitReporterTests" name="testReporterShouldReturnXMLForFailedTest" time="0.000516057014465332"></testcase>
  </testsuite>
  <testsuite tests="1" failures="1" disabled="0" errors="0" time="0.00021898746490478516" name="UtilsTests">
    <testcase classname="SwiftTestReporterTests.UtilsTests" name="testShouldReturnProperlyClassName" time="0.00021898746490478516">
      <failure message="Oh no!!"></failure>
    </testcase>
  </testsuite>
</testsuites>

如何使用?

Linux

SwiftTestReporter 添加到 Package.swift

import PackageDescription

let package = Package(
  dependencies: [
    ...
    .package(url: "https://github.com/allegro/swift-junit.git", from: "2.0.0"),
    // or for Swift 4.x
    // .package(url: "https://github.com/allegro/swift-junit.git", from: .upToNextMajor(from: "1.0.0")),
                
  ]
  ...
  targets: [
    ...
    .testTarget(
      name: "AppTests",
      dependencies: [
        "App",
        "SwiftTestReporter"
      ]
    ),
  ]
)

接下来,添加

import SwiftTestReporter

_ = TestObserver()

LinuxMain.swift。完成。

XCode

项目导航器中,选择特定的项目

test

接下来,选择测试目标

test

添加一个名为Principal class的新属性,并将其设置为SwiftTestReporter.TestObserver

test