Conditional Test Execution
Widely used in testing.
Determined on runtime.
What’s new?
In Xcode 12 we can use XCTSkip for tests that require conditional test execution. It will give us one of the following result:
Pass
Fail
Skip
Examples
guard #available(iOS 13.4, *) else {
throw XCTSkip("Pointer interaction tests can only run on iOS 13.4")
}Our test will only run on iOS 13.4 or later: if the device running the test has a lower OS, then XCTSkip will be throw and the test is skipped.
We can also add conditions based on the device:
try XCTSkipIf(UIDevice.current.userInterfaceIdiom != .pad, "Pointer interaction tests are for iPad only")Tests will be marked with gray color when skipped, and there will be an annotation to track the specified location skipped in the code.

We’re also able to check the results from the test navigator and test report. With the test report we can also see the reason why and where is the location of the skipped test
How does it look like in CI? See below:

APIs
There are 2 throwing function:
XCTSkipIf: Skipa test if expression istrueXCTSkipUnless: Skip test if expression isfalse
public func XCTSkipIf(
_ expression: @autoclosure () throws -> Bool,
_ message: @autoclosure () -> String? = nil,
file: StaticString = #filePath,
line: UInt = #line
) throws
public func XCTSkipUnless(
_ expression: @autoclosure () throws -> Bool,
_ message: @autoclosure () -> String? = nil,
file: StaticString = #filePath,
line: UInt = #line
) throwsTests also can throw XCTSkip directly:
public struct XCTSkip: Error {
public init(_ message: String? = nil, file: StaticString = #filePath, line: UInt = #line)
}