Win a ticket for the Do iOS Conference in Amsterdam Join here.
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

Join 20,033 Swift developers in our exclusive newsletter for the latest insights, tips, and updates. 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: 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()
mainApp.launch()

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.

 
Antoine van der Lee

Written by

Antoine van der Lee

iOS Developer since 2010, former Staff iOS Engineer at WeTransfer and currently full-time Indie Developer & Founder at SwiftLee. Writing a new blog post every week related to Swift, iOS and Xcode. Regular speaker and workshop host.

Are you ready to

Turn your side projects into independence?

Learn my proven steps to transform your passion into profit.