SolvedCocoaPods Modules not found in test targets
โ๏ธAccepted Answer
Thanks for the great ticket! So, pods would be passed to a target by inheritance here, but you're not inheriting them. To quote the guide
platform :ios, '9.0'
inhibit_all_warnings!
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
# Has it's own copy of OCMock
# and has access to GoogleAnalytics via the app
# that hosts the test target
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
So in this case you want to do something like:
target 'Demo App' do
pod 'Alamofire'
target 'Demo AppTests' do
inherit! :search_paths
pod 'OHHTTPStubs'
end
target 'Demo AppUITests' do
inherit! :search_paths
pod 'OHHTTPStubs'
end
end
Though I bet you could improve that even further, I think, this is guesswork now though:
target 'Demo App'
pod 'Alamofire'
abstract_target 'tests' do
target 'Demo AppTests'
target 'Demo AppUITests'
inherit! :search_paths
pod 'OHHTTPStubs'
end
Other Answers:
I believe this thread got off-topic. The initial issue is not the inheritance, but the fact that adding a pod to a test target doesn't work, as xCode says No Such Module 'Quick'. Is there any official fix for this? or maybe an official extra step that we need to do, that is not documented?
@AshleyDeng I got quite a long list of schemes, have you found a solution since that doesn't require all this manual work
Running pod deintegrate
, changing the Podfile to
platform :ios, '9.0'
use_frameworks!
target 'Demo App' do
pod 'Alamofire'
abstract_target 'tests' do
platform :ios, '9.0'
target 'Demo AppTests'
target 'Demo AppUITests'
inherit! :search_paths
pod 'OHHTTPStubs'
end
end
and using CocoaPods/Core#308 together fix the issue
I know this issue has been closed but I just experienced this issue with Cocoapods 1.0.0 and the way i solved it is as follows... When I tried the new cocoapods 1.0.0 syntax for the Podfile like so:
target 'Chat_Example' do
pod 'ChatKit', :path => '../'
target 'Chat_Example_Tests' do
inherit! :search_paths
end
end
then my test target was not able to import the ChatKit module. However if I write the Podfile as so
then the tests are able to import the module:
def reusepods
pod 'ChatKit', :path => '../'
end
target 'Chat_Example' do
reusepods
end
target 'Chat_Example_Tests' do
reusepods
end
Report
I am having trouble with "No such module 'MODULE_NAME'" errors.
Example Project
What did you do?
pod init
pod install --verbose
Error on
import Alamofire
was "No such module 'Alamofire'".Error on
import OHHTTPStubs
was "No such module 'OHHTTPStubs'".NOTE: Adding
pod 'Alamofire'
to the testing targets also results in the same behaviour.These errors would sometimes disappear for around ~5 secs or until a key was pressed to make a change to the swift file if I build the targets generated by CocoaPods or ran both
CMD + SHIFT + U
andCMD + SHIFT + R
.Sometimes running
CMD + U
would let the test target compile and other times it would not.I have also tried clearing derived data.
What did you expected to happen?
I expected that the pod Alamofire would be available for use in all targets.
I expected that the pod OHHTTPStubs would be available for use in all test targets.
What happened instead?
In the test targets the modules Alamofire and OHHTTPStubs could not be found.
That is:
Pod Alamofire is missing from the targets "Demo AppTests" and "Demo AppUITests".
Pod OHHTTPStubs is missing from the targets "Demo AppTests" and "Demo AppUITests".
Pod Env
Stack
Installation Source
Plugins
Podfile