/SignpostTestObserver.swift Secret
Created
July 8, 2018 23:17
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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