Search code examples
objective-casynchronousxctestunit-testing

Unit testing asychronous UI code which does not know about XCTestExpectations?


How can one go about unit-testing pieces of iOS code that work in a non-trivial graphical setup?

Consider for instance view controllers A and B, where A stacks B on top with performSegueWithIdentifier:sender:. A unit test should check the behavior of a C that depends on the two view controllers being arranged like that.

performSegueWithIdentifier:sender: works asynchronously, i.e. the unit test would end before it has completed its task unless one lets the unit test wait for something like an XCTestExpectation. But in a case like this neither B nor C is prepared to call fulfill on that expectation.

Is there a way forward in situations like this, i.e. for testing asynchronous UI code without ready hooks for calling fulfill?


Solution

  • I have concluded that employing an integration test framework (such as KIF) is probably the way to go.