UI Tests are a great tool to validate your application. It is easy to create them for your main application, but it might be harder to create a UI test for your share extension. This can be just as easy as your main application with some simple steps.
UI Test steps
A UI test for testing the extension needs a few extra steps.
- Launch an external app, for example, Safari
- Navigate to some sharable content
- Open the share sheet
- Enable the extension for your application
- Open the extension for your application
After that, you should be able to interact with your extension.
Share extension UI Test example
To make this really easy, I’ve written an extension which can be found here: https://gist.github.com/AvdLee/719b2de80d74fc503ca1c64a23706d93.
This results in just a few lines of code before you can start interacting with your share extension:
// start main app to make sure the Share Extension exists.
let mainApp = XCUIApplication()
let safariApp = openSafari(with: URL(string: "https://www.avanderlee.com")!)
openShareExtension(name: "Example Share Extension", in: safariApp)
This video will show you how a certain UI Test run would look:
This video is directly recorded from the simulator using simctl. Read more about it here.