Testing XPC services

Ilya Kulakov
1 min readJun 24, 2020

Xcode test bundles are actually executables that may embed everything a regular app can. This allows testing of embedded XPC services without employing any shenanigans:

  1. Add new Unit Test target
  2. Add the Copy Files phase to the created target with “XPC Services” as a destination; drag’n’drop your XPC service there
  3. Optionally add another Copy Files phase with “Frameworks” as a destination for every custom framework the service depends on; make sure that the Copy on Sign is checked if your XPC service is sandboxed and/or hardened
  4. Open the Schemes editor via Product → Schemes → Manage Schemes…
  5. Delete Unit Test’s scheme
  6. Select XPC service’s scheme and click Edit…
  7. Select the Test step, navigate to Info and add the Unit Test

To communicate with the XPC service from within tests set up NSXPCConnection as usual and employ help of XCTestExpectation for synchronization.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Ilya Kulakov
Ilya Kulakov

Written by Ilya Kulakov

Tech Entrepreneur and Quality Freak with passion.

No responses yet

Write a response