iOS Testing: Is there a way to skip tests?

scrrr picture scrrr · May 27, 2015 · Viewed 15.1k times · Source

I don't want to execute certain tests if the feature is currently disabled. Is there a way to "skip" a test (and to get appropriate feedback on console)?

Something like this:

func testSomething() {
  if !isEnabled(feature: Feature) {
    skip("Test skipped, feature \(feature.name) is currently disabled.")
  }

  // actual test code with assertions here, but not run if skip above called.
}

Answer

Sandy Chapman picture Sandy Chapman · Apr 20, 2016

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.