iOS - 运行Swift的单元测试时找不到“MyProject-Swift.h”文件 [英] iOS - 'MyProject-Swift.h' file not found when running Unit Tests for Swift
问题描述
我正在为我的项目设置单元测试。
这是一个现有的Objective-C应用程序,我最近添加了一个Swift类。我已经设置了'MyProject-Swift.h'和Swift Bridging文件('MyProject'和'MyProjectTest'),并且我可以使用Objective-C和Swift代码很好地构建和运行应用程序。
然而,现在我想在新的Swift类上运行一些单元测试。
我设置了我的测试文件,它看起来像下面这样:
MySwiftClassTests.swift:
import UIKit
import XCTest
import MyProject
class MySwiftClassTests:XCTestCase {
覆盖func setUp(){
super.setUp()
//将设置代码放在这里。在调用该类中的每个测试方法之前调用此方法。
}
覆盖func tearDown(){
//将拆卸代码放在这里。调用该类中的每个测试方法后调用此方法。
super.tearDown()
}
func testExample(){
//这是一个功能测试用例的例子。
XCTAssert(true,Pass)
}
func testPerformanceExample(){
//这是性能测试用例的一个例子。
self.measureBlock(){
//把你想要测量的代码放在这里。
$ b
我得到运行应用程序时出现此错误:
'MyProject-Swift.h'文件未找到
我不确定为什么只有在尝试运行测试时才会出现这种情况。
有何建议?
MyProject-Swift.h以下路径:
$(TARGET_TEMP_DIR)/../$(PROJECT_NAME).build / DerivedSources
我最终将这个添加到我的单元测试目标的Header搜索路径中。
同样@hyouuu指出关于成为已知问题,希望苹果能够在他们的最后提供一些很好的解决方案。直到我相信我们需要使用这个上面的解决方案。
I am trying to setup Unit Testing for my project. It is an existing Objective-C app, that I have recently added one Swift class to. I have setup the 'MyProject-Swift.h' and Swift Bridging files (both 'MyProject' and 'MyProjectTest') and I am able to build and run the app just fine using both Objective-C and Swift code.
However, now I want to run some Unit Tests on the new Swift class. I setup my test file and it looks like the following:
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.
}
}
}
I get this error when running the app as Test:
'MyProject-Swift.h' file not found
I am not sure why this happens only when trying to run the Tests. Any suggestions?
"MyProject-Swift.h" file is generated at following path:
"$(TARGET_TEMP_DIR)/../$(PROJECT_NAME).build/DerivedSources"
I end up adding this to Header Search Paths for my Unit Test target.
Also as @hyouuu pointed out about being the known issue, hopefully Apple will provide some good solution at their end. Until I believe we need to use this above solution.
这篇关于iOS - 运行Swift的单元测试时找不到“MyProject-Swift.h”文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!