Unit Testing an iOS Action Extension

Hi,


I developed an application with an action extension bundled in it. I am able to unit test the application using traditional way but not the action extension.

I went through the apple docs which says "To test an app extension using the Xcode testing framework (that is, the XCTest APIs), write tests that exercise the extension code using your containing app as the host environment. To learn more about testing, see Testing with Xcode.", which is not very helpful.

This links says

https://stackoverflow.com/questions/24627600/how-to-unit-test-an-app-extension-on-xcode-6

unit testing is not supported currently but this is an old post.

The answer here depends on what you mean by “unit testing”. Most app extensions are structured as a top-level NSExtension subclass that’s implemented in terms of many different lower-level subsystems. You test those lower-level subsystems via the usual means (you isolate them into units and test those units independently). Such testing can be done in your normal app environment because you’ve already done the relevant isolation.

Testing the top-level NSExtension subclass is tricky because that’s not an easily isolated unit. My general advice on that front is to move as much code as possible out of that subclass into separate subsystems that you can test. At that point the NSExtension subclass is really just an integration point, and you test that via your integration tests.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Unit Testing an iOS Action Extension
 
 
Q