我正在尝试为我的项目设置单元测试。
它是一个现有的 Objective-C 应用程序,我最近向其中添加了一个 Swift 类。我已经设置了“MyProject-Swift.h”和 Swift 桥接文件(“MyProject”和“MyProjectTest”),并且我能够使用 Objective-C 和 Swift 代码很好地构建和运行应用程序。
但是,现在我想在新的 Swift 类上运行一些单元测试。
我设置了测试文件,如下所示:
MySwiftClassTests.swift:
import UIKit
import XCTest
import MyProject
class MySwiftClassTests: 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.measureBlock() {
// Put the code you want to measure the time of here.
}
}
}
作为测试运行应用程序时出现此错误:
'MyProject-Swift.h' file not found
我不确定为什么只有在尝试运行测试时才会发生这种情况。
有什么建议么?
“MyProject-Swift.h”文件在以下路径生成:
"$(TARGET_TEMP_DIR)/../$(PROJECT_NAME).build/DerivedSources"
我最终将其添加到我的单元测试目标的标头搜索路径中。
另外,正如 @hyouuu 指出的已知问题,希望苹果最终能提供一些好的解决方案。直到我相信我们需要使用上述解决方案。
https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc6_release_notes.html https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc6_release_notes.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)