Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing iOS app extension

My iOS app has multiple extensions:

  • today extension

  • siri extension

  • imessage extension

Also I created framework to share common code. My problem is that I want to have one unit test target which will test all extension. My Podfile looks like this:

 target 'MyApp' do
   pod 'MyFramework', :path => './MyFramework'
     target 'MyAppTests' do
       inherit! :search_paths
     end
 end

abstract_target 'Extensions' do
  pod 'MyFramework', :path => './MyFramework'
  target 'TodayExtension'
  target 'SiriExtension'
  target 'iMessageExtension'
  target 'ExtensionsTests'
end

As you see I created ExtensionsTests target but I don't know how I can inherit search path of all extensions. I also tried to use @testable import TodayExtension but I get linked error for undefined symbols for architecture x86_64.

Any ideas how I can fix this?

Complete error code:

Undefined symbols for architecture x86_64:
  "type metadata accessor for TodayExtension.LoadingView", referenced from:
      ExtensionTests.LoadingViewTests.setUp () -> () in LoadingViewTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

EDIT:

I think that problem is general: how I can test any extension code? I created single view project, added today extension and I'm not able to extension code.

In apple docs there is only this information:

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

like image 979
MichalMoskala Avatar asked Nov 14 '16 10:11

MichalMoskala


1 Answers

I ran into the same issue. According to this answer, unit testing extensions in this way is unsupported. As a workaround, you can factor out the code you’d like to test into a framework and include it in both your extension target and in your extension test target.

like image 51
paulrehkugler Avatar answered Oct 12 '22 03:10

paulrehkugler