Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Testing: Is there a way to skip tests?

Tags:

ios

swift

xctest

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. } 
like image 786
scrrr Avatar asked May 27 '15 09:05

scrrr


People also ask

How do you skip test jest?

To skip one test in test file with Jest, we can call test. skip in our test code. For instance, we write: test('it is delicious', () => { expect(isDelicious()).

Why test cases are skipped?

The most common reason for the test cases getting skipped with Selenium using TestNG is if your methods are dependent on other method and a method you depend on is failed.

How do I use XCTSkip?

You need to throw the XCTSkip , since it is an Error , simply creating it has no effect on your test outcome. Or you can use the XCTSkipIf function, which skips the test in case the passed in condition is met. So in the tests you want to skip, just call XCTSkipIf(shouldSkip) .

Should I include tests Xcode?

You do not need to include unit tests. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application.


2 Answers

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.

like image 171
Sandy Chapman Avatar answered Sep 21 '22 08:09

Sandy Chapman


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 ""
like image 35
Alexander Doloz Avatar answered Sep 20 '22 08:09

Alexander Doloz