概要
XCTSkipを実行し、条件に合わせてテストがランタイム中に開始しないようにする方法及び、様々なテストの中で単にpassとfailだけではないドキュメントテストの実施方法について iPhone/iPad特有のコード、OS versionによって利用可能なAPI、ネットワーク環境に依存するコードなど様々なケースにおいてテストが必要とされます

そこで利用するのが
XCTSkip
です
XCTSkipについて
- Xcode 11.4から利用可能なAPI
- テストの結果は下記3種類となる
- Pass
- Fail
- Skip
Sample code
iPadの場合はSkipするfunc testExample() throws {
/// Example usage: skip test if device is not an iPad
// XCTSkipIf(UIDevice.current.userInterfaceIdiom != .pad でもOK
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad,
"Pointer interaction tests are for iPad only")
// test...
}
func testExample() throws {
/// Example usage: skip test if OS version is older than iOS 13.4
guard #available(iOS 13.4, *) else {
throw XCTSkip("Pointer interaction tests can only run on iOS 13.4+")
// test...
}
例えば、「iPadではSkipし、iPhoneではPassとなった」など。