我正在尝试为我的iOS应用程序创建自动UI测试。在通常无法在现有应用程序上运行之后,我从头开始创建一个新的并在那里尝试。它似乎总是失败,因为它无法导入我用Cocoapods安装的依赖项。
我目前正在运行XCode版本10.2.1(10E1001)
复制说明:
UITestProto
pod init
。HydraAsync
依赖项Podfile应如下所示:
# 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
目标的Build Settings,并将“Always Embed Swift Standard Libraries”设置为$(inherited)
:pod install
UITestProto.xcworkspace
打开项目UITestProtoUITests.swift
文件并尝试导入OHHTTPStubs模块。import XCTest
import Hydra
class UITestProtoUITests: XCTestCase {
...
此时您应该看到错误:
没有这样的模块'Hydra'
我试过了:
@testable import UITestProto
因为我必须为我的单元测试做到这一点我已经清理了构建文件夹并在每个步骤之后关闭/打开了XCode,但是在Hydra导入上仍然没有运气。
注意:我实际上并没有使用Hydra进行测试,它只是我过去在项目中成功使用的库
这与CocoaPods issue有关。解决方法建议here为我做的伎俩。您可能需要重建项目。
为了将来参考,我已经发布了帖子:
# 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
积分兑换PWrzesinski
试试这个:
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
并在此之后运行pod deintegrate
和pod update && pod install
。