Handling Flaky Tests

When running tests, sometimes you may discover that some tests just fail sporadically. This may be due to conditions on the test host or perhaps some unexpected downtime in a service. It could even be caused by using test randomization. Regardless of the cause, the goal is to have all tests passing at all times and that does become difficult if there are external dependencies or resource issues. XCTest provides some utilities to help us make robust tests that can handle this....

Controlling Test Executions

When running unit tests (and UI tests), XCTest provides a few ways of interacting with the test runner. The most common scenario for interacting with your own tests is to provide common code to run before tests start and when they finish to ensure that each test has a clean environment. Setup and Tear Down XCTestCase provides APIs to modify the test environment before and after all tests have executed, but also before and after individual tests have run....