iOS Testing: Is there a way to skip tests? iOS Testing: Is there a way to skip tests? swift swift

iOS Testing: Is there a way to skip tests?


You can disable XCTests run by Xcode by right clicking on the test symbol in the editor tray on the left.

enter image description here

You'll get this menu, and you can select the "Disable " option.

enter image description here

Right clicking again will allow you to re-enable. Also, as stated in user @sethf's answer, you'll see entries for currently disabled tests in your .xcscheme file.

As a final note, I'd recommend against disabling a test and committing the disabling code in your xcscheme. Tests are meant to fail, not be silenced because they're inconvenient.


Another possible solution which I found in some article: prefix your skipped tests with something like "skipped_"

Benefits:

  • XCode will not treat them as tests
  • You can easily find them using search
  • You can make them tests again, replacing "skipped_" to ""


Beginning with Xcode 11.4 you'll be able to using XCTSkipUnless(_:_:file:line:).

The release notes read,

XCTest now supports dynamically skipping tests based on runtimeconditions, such as only executing some tests when running on certaindevice types or when a remote server is accessible. When a test isskipped, Xcode displays it differently in the Test Navigator and TestReport, and highlights the line of code where the skip occurred alongwith an optional user description. Information about skipped tests isalso included in the .xcresult for programmatic access.

To skip a test, call one of the new XCTSkip* functions from within atest method or setUp(). For example:

func test_canAuthenticate() throws {    try XCTSkipIf(AuthManager.canAccessServer == false, "Can't access server")    // Perform test… }

The XCTSkipUnless(::file:line:) API is similar toXCTSkipIf(::file:line:) but skips if the provided expression isfalse instead of true, and the XCTSkip API can be used to skipunconditionally. (13696693)