Key Takeaways

Sometimes tests need to downcast an object to a more specific type so it can query its properties. A force-cast as! is simple but will crash the test run if the type is wrong. Use the softer conditional cast as? with a guard let. If the guard fails, use an XCTFail to report the desired type and the actual object.

“Execute the run loop” is a good trick to keep in your pocket. When things work in manual testing but not in unit testing, see if the trick works. Sometimes it gives UIKit that extra kick it needs.

To test code-based push navigation, follow these steps:

To test code-based modal navigation, follow these steps:

To test segue-based push navigation, follow these steps:

To test segue-based modal navigation, follow these steps: