我正在爲我的(macOS)Xcode項目嘗試編寫單元測試(不是 UI測試)。我創建了一個新的單元測試目標,爲我創建一個空白單元測試文件。Swift 3單元測試 - 使用導入時鏈接器失敗@testable
這符合和鏈接很好,但沒有測試。
只要我添加一行@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.
}
}
}
這指出我在正確的方向。結果我的CocoaPods框架沒有包含在測試目標中(不是CocoaPods 1.0.0之前的問題),所以修復它解決了我的鏈接問題。謝謝! – Rohan