Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import XCTest
import os.log
import os.signpost
// Add to your test suite "Info.plist": "Principal class" => "$(PRODUCT_NAME).TestObserver"
class SignpostTestObserver: NSObject, XCTestObservation {
lazy var log: OSLog = {
return OSLog(subsystem: "net.davelyon.os-log-test", category: "example")
}()
override init() {
super.init()
// XCTestObservation keeps a strong reference to observers
XCTestObservationCenter.shared.addTestObserver(self)
}
// MARK: - Test Bundle
func testBundleWillStart(_ testBundle: Bundle) {
let id = OSSignpostID(log: log, object: testBundle)
os_signpost(.begin, log: log, name: "test bundle", signpostID: id, "%@", testBundle.description)
}
public func testBundleDidFinish(_ testBundle: Bundle) {
let id = OSSignpostID(log: log, object: testBundle)
os_signpost(.end, log: log, name: "test bundle", signpostID: id, "%@", testBundle.description)
}
// MARK: - Test Suite
func testSuiteWillStart(_ testSuite: XCTestSuite) {
let id = OSSignpostID(log: log, object: testSuite)
os_signpost(.begin, log: log, name: "test suite", signpostID: id, "%@", testSuite.name)
}
func testSuiteDidFinish(_ testSuite: XCTestSuite) {
let id = OSSignpostID(log: log, object: testSuite)
os_signpost(.end, log: log, name: "test suite", signpostID: id, "%@, duration: %f", testSuite.name, testSuite.testRun!.testDuration)
}
func testSuite(_ testSuite: XCTestSuite, didFailWithDescription description: String,
inFile filePath: String?, atLine lineNumber: Int) {
let id = OSSignpostID(log: log, object: testSuite)
os_signpost(.event, log: log, name: "test suite failure", signpostID: id)
}
// MARK: - Test Case
func testCaseWillStart(_ testCase: XCTestCase) {
let id = OSSignpostID(log: log, object: testCase)
os_signpost(.begin, log: log, name: "test case", signpostID: id, "%@", testCase.name)
}
func testCaseDidFinish(_ testCase: XCTestCase) {
let id = OSSignpostID(log: log, object: testCase)
os_signpost(.end, log: log, name: "test case", signpostID: id, "%@, duration: %f", testCase.name, testCase.testRun!.testDuration)
}
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String,
inFile filePath: String?, atLine lineNumber: Int) {
let id = OSSignpostID(log: log, object: testCase)
os_signpost(.event, log: log, name: "test case failure", signpostID: id)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.