7
votes

I've noticed recently that @testable import doesn't seem to work for Watch Extension modules.

Here's what I've tried so far:

  • Create a new Xcode project with WatchKit app and include unit tests.
  • Open the auto created unit tests file and add @testable import ProjectName_WatchKit_Extension (after confirming that this is the correct module name in the extension's build settings). This gives a 'no such module' compiler error.
  • Confirm that 'Enable testability' is set to yes in Extension build settings.
  • Change name of Extension module to remove spaces

I am of course able to successfully unit test by adding the required files to the test target, but it feels like this should not be necessary.

Has anyone been able to successfully use @testable import with a Watch Extension? Is this something I should be able to do? Any help would be much appreciated.

1
Is there any solution to this now?Ramya

1 Answers

0
votes

From an Instagram library IGInterfaceDataTable: https://github.com/facebookarchive/IGInterfaceDataTable/tree/e5565a96c5a71ef7b849920adc34f880cc37dc03#testing

Since WKInterfaceTable objects must be initialized from storyboards, and 
there is no mechanism yet to create a WatchKit storyboard in code, we cannot use 
Xcode unit tests yet.

For now, tests are run manually by executing the ApplicationTests WatchKit 
extension and ensuring that none of the asserts are fired.

This is a good question, I saw a similar issue was opened against Quick and Nimble testing framework which talks about the lack of support for watch kit extension testing. Take a look: https://github.com/Quick/Quick/issues/273.