Given the following setup:
How can the document-based parts of the app be UI-tested with the XCTest framework?
Regular unit or UI tests not related to the document-based functionality are easy, but I cannot see how to do UI tests on the document-based bit, given that in UI tests we are forbidden from reaching into the app and, for example, mocking the NSDocument class.
One suggestion I've heard is to create fixture files / folders (depending on what your document-based app needs) in the test resources folder, and somehow get the test to open that. But is there any better solution?
The person who made the fixtures suggestion is pretty much spot-on. Since the UI Tests are supposed to exercise exactly the functionality of the app without reaching into the internals, you'll have to load the documents externally.
XCTest is not (as of Xcode 7.x + El Capitan) able to drive the File -> Open... -> Select a file -> Click 'Open' button flow - it gets as far as the Open... dialog and then the test crashes because it cannot proceed further. This means you won't be able to open the document via the UI.
This leaves only one other option - you should try to initialize the app through some sort of passed argument in init to lob the necessary local state in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With