Why won't unit tests build when the test target is excluded from CocoaPods management?

Viewed 103

I'm hoping to gain a clear understanding of the interaction between CocoaPods and unit test targets.

Let's assume a simple Podfile

platform :ios, '13.0'

target 'CocoaPodsTest' do
  use_frameworks!

  pod 'FBSDKCoreKit', '~>7.0'
  pod 'Firebase/Analytics', '~>6.8'

  target 'CocoaPodsTestTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

My unit test target - CocoaPodsTestTests - doesn't use any testing frameworks. It just has plain ol' XCTest asserts that exercise source code from the app target. I understand that it inherits the dependencies from the app target, but I'm not importing those modules. In my unit test source files, I'm only @testable import CocoaPodsTest to give myself access to the internal API of my different types.

When I remove the unit test target from the Podfile and then do a pod install, CocoaPods stops managing this target. Specifically, the test target is not linked with the CocoaPods framework - Pods_CocoaPodsTestTests.framework. There are a handful of other changes, and these are totally expected.

What's not expected is that now CocoaPodsTestTests target will not build. It fails with the error: Mising required module 'Firebase' and points to the line where I've @testable import'ed the app module.

Why does my unit test target have third-party dependencies?

I thought that...

... CocoaPods created a framework from third-party resources ...

... the app embedded and linked the CocoaPods framework ...

... and, finally, the unit test target was dynamically injected into the running app, therefore resolving the test target's dependency on the app module.

But, there's obviously a hole in my knowledge.

0 Answers
Related