【发布时间】:2020-07-26 12:33:48
【问题描述】:
我在 iOS 方面相当缺乏经验。我想为我的 Cocoapods 项目编写单元测试。
我要测试的 ViewController 位于 Pod 中。当我想编写单元测试时,我已经收到一条错误消息
import MyApplication
上面写着
No such module 'MyApplication'
请注意,我仅使用“MyApplication”来代替我在图片中用红色划掉的原始名称。
有什么问题?
编辑:
我的测试类代码:
import UIKit
import XCTest
import Pods_MyApplication_Example
@testable import Pods_MyApplication
class Tests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
XCTAssert(true, "Pass")
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure() {
// Put the code you want to measure the time of here.
}
}
}
要创建测试目标,请在测试导航器上单击“+”,然后选择“新建单元测试目标”
如果有任何信息丢失,我很抱歉。有的话我会加的!
EDIT2:更改的图片可能会提供更多信息
【问题讨论】:
-
您要导入的 Pods_MyApplication_Example 模块是什么?如果删除 import Pods_MyApplication_Example 行会发生什么?
-
感谢您的评论,很抱歉回复晚了。 MyApplication_Example 是 MyApplication 的目标。但是删除该导入行并不能解决错误消息。
-
MyApplication_Example 是应用程序目标。这就是您必须在 @testable 导入中提供的内容。我更新了答案。
标签: ios swift xcode cocoa-touch cocoapods