【发布时间】:2017-04-12 01:54:45
【问题描述】:
我目前正在尝试为我的 (macOS) Xcode 项目编写单元测试(NOT UI 测试)。我创建了一个新的单元测试目标,它为我创建了一个空白单元测试文件。
这符合并链接正常,但没有测试。
只要我添加行@testable import Pilot,其中Pilot 是我的应用程序目标的名称,我尝试编译和运行,它就会失败并显示以下消息:
Linker command failed with exit code 1 (use -v to see invocation)
我已经尝试了所有能找到的方法,但似乎没有任何效果。我在这里阅读的其他帖子在 UI 测试中处理了这个问题,但那是因为您不能在 UI 测试中使用 @testable。您应该能够在单元测试中使用它,但我无法弄清楚为什么这不起作用。
有人有什么见解吗?
如果有帮助,我的项目位于:https://github.com/RohanNagar/pilot-osx
这是完整的PilotTests.swift 文件:
import XCTest
@testable import Pilot
class PilotTests: 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.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
【问题讨论】:
标签: swift xcode unit-testing cocoa linker