Xcode stop UI testing on any single test failure

Is there a way to stop the whole UI tests execution on a single test failure? I'm already using continueAfterFailure flag which stops further test execution for that particular test suite. But this does not suit our requirement since it will jump to next test suite and execute tests further.

Any help would be appreciated, thanks.

Accepted Reply

Hello! Thanks for your question.

There doesn't seem to be an officially supported way to do this. That said, if you subclass XCTestCase and add your own properties to it, you can create a workaround.

https://developer.apple.com/documentation/xctest/xctestcase/3546549-record

The record(_:) method is called every time a test fails or an issue occurs. If you subclass XCTestCase and override this method (making sure to call super.record(_:)), you should be able to get the behavior you desire using any number of methods.

One way to go about this would be to add a boolean property to your XCTestCase subclass that becomes true if any single test has failed, then skips any additional tests from inside the setUpWithError() method once that boolean has been set.

https://developer.apple.com/documentation/xctest/xctest/3521150-setupwitherror

https://developer.apple.com/documentation/xctest/methods_for_skipping_tests

  • This workaround worked for me. Although had to do further workaround to persist the boolean property across test suites. Appreciate you help, thanks.

  • This workaround worked for me. Although had to do further workaround to persist the boolean property across test suites. Appreciate you help, thanks.

Add a Comment

Replies

Hello! Thanks for your question.

There doesn't seem to be an officially supported way to do this. That said, if you subclass XCTestCase and add your own properties to it, you can create a workaround.

https://developer.apple.com/documentation/xctest/xctestcase/3546549-record

The record(_:) method is called every time a test fails or an issue occurs. If you subclass XCTestCase and override this method (making sure to call super.record(_:)), you should be able to get the behavior you desire using any number of methods.

One way to go about this would be to add a boolean property to your XCTestCase subclass that becomes true if any single test has failed, then skips any additional tests from inside the setUpWithError() method once that boolean has been set.

https://developer.apple.com/documentation/xctest/xctest/3521150-setupwitherror

https://developer.apple.com/documentation/xctest/methods_for_skipping_tests

  • This workaround worked for me. Although had to do further workaround to persist the boolean property across test suites. Appreciate you help, thanks.

  • This workaround worked for me. Although had to do further workaround to persist the boolean property across test suites. Appreciate you help, thanks.

Add a Comment