Reporting to iOS XCTest (Swift)
To set up your own XCTestCase in Swift that makes use of cavy-native-reporter:
- Follow the same steps as for the Objective-C setup, but choose Swift when prompted to choose a language.
- Make sure that a Bridging Header file has also been created (Xcode will usually prompt you to create one if this is your first Swift file in the project).
- Import <CavyNativeReporter/CavyNativeReporter.h>in your Bridging Header.
- Write a test.
The following Swift code is equivalent to the Objective-C example:
import XCTest
class BridgeTest: XCTestCase {
  func testBridge() {
    let expectation = XCTestExpectation(description: "Cavy tests passed")
    CavyNativeReporter.onFinish { report in
      NSLog("%@", report)
      let errorCount = report["errorCount"] as? Int ?? 0
      if errorCount > 0 {
        XCTFail("Cavy tests had one or more errors")
      }
      expectation.fulfill()
    }
    wait(for: [expectation], timeout: 5)
  }
}