iOS - 运行 Swift 单元测试时找不到“MyProject-Swift.h"文件 [英] iOS - 'MyProject-Swift.h' file not found when running Unit Tests for Swift

查看:30
本文介绍了iOS - 运行 Swift 单元测试时找不到“MyProject-Swift.h"文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的项目设置单元测试.这是一个现有的 Objective-C 应用程序,我最近添加了一个 Swift 类.我已经设置了MyProject-Swift.h"和 Swift 桥接文件(MyProject"和MyProjectTest"),并且我能够使用 Objective-C 和 Swift 代码构建和运行该应用程序.

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.

但是,现在我想在新的 Swift 类上运行一些单元测试.我设置了我的测试文件,它看起来像下面这样:

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" 文件在以下路径生成:

"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.

此外,正如@hyouuu 指出的已知问题,希望 Apple 最终能提供一些好的解决方案.直到我相信我们需要使用上述解决方案.

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.

https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc6_release_notes.html

这篇关于iOS - 运行 Swift 单元测试时找不到“MyProject-Swift.h"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆