Give your simulator superpowers

RocketSim: An Essential Developer Tool
as recommended by Apple

Share Extension UI Tests written in Swift

Stay updated with the latest in Swift

The 2nd largest newsletter in the Apple development community with 19,438 developers. Don't miss out – Join today:

You can always unsubscribe, no hard feelings.

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.

  1. Launch an external app, for example, Safari
  2. Navigate to some sharable content
  3. Open the share sheet
  4. Enable the extension for your application
  5. 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:

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: "")!)
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.