Reputation: 2243
I'm trying to create automated UI tests for my iOS app. After generally failing to get this working on my existing app, I created a new one from scratch and tried there. It always seems to fail because it can't import dependencies I've installed with Cocoapods.
I'm currently running XCode Version 10.2.1 (10E1001)
Instructions to replicate:
UITestProto
pod init
on the project.HydraAsync
dependencyThe Podfile should look like this:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.2'
target 'UITestProto' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for UITestProto
target 'UITestProtoTests' do
inherit! :search_paths
# Pods for testing
end
target 'UITestProtoUITests' do
inherit! :search_paths
# Pods for testing
pod 'HydraAsync'
end
end
UITestProtoUITests
target in XCode and set "Always Embed Swift Standard Libraries" to $(inherited)
:pod install
UITestProto.xcworkspace
UITestProtoUITests.swift
file and try to import the OHHTTPStubs module.import XCTest
import Hydra
class UITestProtoUITests: XCTestCase {
...
At this point you should see the error:
No such module 'Hydra'
I've tried:
@testable import UITestProto
because I've had to do that for my unit testsAnd I've cleaned the build folder and closed/open XCode after each of those steps, but still no luck on the Hydra import.
Note: I'm not actually using Hydra for testing, it's just a library that I've successfully used in projects in the past
Upvotes: 3
Views: 8304
Reputation: 1556
Same behaviour still with XCode 12.3 in 2021. Easy fix for me by just running the tests once.
I had the same issue with another pod added to the unit tests or UI tests. The podfile had the pod in the right target section. So it should recognize it.
The error went away as soon as I ran the tests (Cmd+U
)
Only building or running it is not enough since it won't try to build anything of the test targets.
The same problem sometimes happens when adding a new module, class etc. but also fixes itself after building the propper target.
Upvotes: 1
Reputation: 4909
This is related to a CocoaPods issue. The workaround suggested here does the trick for me. You may need to rebuild the project though.
For future reference, I've cc-ed the post:
# Moving the UITests target outside of the main target
# in the Podfile seems to have helped. So now instead of this:
target 'Target' do
use_frameworks!
...
target 'TargetTests' do
inherit! :search_paths
...
end
target 'TargetUITests' do
inherit! :search_paths
...
end
end
## we have this:
target 'Target' do
use_frameworks!
...
target 'TargetTests' do
inherit! :search_paths
...
end
end
target 'TargetUITests' do
inherit! :search_paths
... # all the pods we normally use
end
Credits to PWrzesinski
Upvotes: 3
Reputation: 1000
Try this:
platform :ios, '12.2'
target 'UITestProto' do
#some pods for your main target
target 'UITestProtoTests' do
inherit! :search_paths
#pods for your unit tests
end
target 'UITestProtoUITests' do
pod 'HydraAsync'
end
end
And run pod deintegrate
and pod update && pod install
after this.
Upvotes: 2