Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift unit test not stopping after XCTFail() has been called

It was my understanding that if you called XCTFail() in one of your unit tests it will fail that test instantly and not carry on and check the remaining assertions. However, this doesn't seem to be the case, at least not in my current project.

We even tried it on a very simple unit test that was passing. We added the XCTFail() before the assertion which caused the unit test to fail but it still carries on and runs the assertion check after the XCTFail().

Is this just a misunderstanding on my part or is something going wrong here? If it is a misunderstanding, what is best practice to tell your unit test to not bother checking the other assertions as you already know they're going to fail?

It's a Swift unit test by the way using the XCTest framework. I've not given a code example as it seems to be the case on every one of our unit tests, no matter how simple they are.

Xcode Version 7.2.1 (7C1002)

like image 990
Hodson Avatar asked Feb 07 '23 09:02

Hodson


1 Answers

You can set continuesAfterFailure to false. Then the test runner stops when one test fails.

like image 108
dasdom Avatar answered Mar 07 '23 01:03

dasdom