Skip to content

Instantly share code, notes, and snippets.

@Caul58
Last active November 14, 2024 14:11
Show Gist options
  • Save Caul58/4ab6b62ad9164c7f6b9a42dfa5fe5bbd to your computer and use it in GitHub Desktop.
Save Caul58/4ab6b62ad9164c7f6b9a42dfa5fe5bbd to your computer and use it in GitHub Desktop.
@available statement in a tests class has just effect for the compiler, not to skip tests contained. So you have to do it manually.
/// First option: if you have a reduced number of tests with this issue.
@available(iOS 17.0, *)
class FirstOptionTests: XCTestCase {
func testStuffOnlyAvailableInIOS17() throws {
guard #available(iOS 17.0, *) else {
throw XCTSkip("Trying to run code in an unsupported iOS version")
}
// All the stuff just available since iOS 17.0
}
}
/// Second option: if you have a lot of tests and you don't want to duplicate the guard
class iOS17TestCase: XCTestCase {
override func invokeTest() {
guard #available(iOS 17.0, *) else {
print("Trying to run code in an unsupported iOS version")
return
}
return super.invokeTest()
}
}
@available(iOS 17.0, *)
class SecondOptionTests: iOS17TestCase {
func testStuffOnlyAvailableInIOS17() throws {
// All the stuff just available since iOS 17.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment