I'm working on a MacOS Document based application that opens a certain file type. What I want to do is write some UI tests for this application, but I want to load some mock data for these UI tests. From what I understand, I should actually use launchArguments or launchEnvironment variables to load this mock data.
So, it sounds to me like the correct thing to do is create some test data files, and open those files at the launch of the application using something like this:
let app = XCUIApplication()
app.launchArguments.append("-url")
app.launchArguments.append($PATH)
app.launch()
Now my question is, where should I add the code for opening a file during launch? Is there a method that NSDocumentDelegate has that I should override? Should I call openDocument(withContentsOf:display:completionHandler:)
or just set the fileURL
or something else entirely?
Right now my application opens the last opened file or opens a new document. I could try to override makeUntitledDocument(ofType typeName: String)
or func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void)
but I don't feel like either of those is the correct option.
So I guess I have two questions: 1) what is the correct way to pass mock data for UI testing of an NSDocument based application. 2) what is the correct way to open a file on launch of an application using a line argument.