我正在学习iOS,现在在为应用程序构建UITest时遇到问题。如果删除var viewController:ViewController,下面粘贴的代码将编译。字段,但添加时失败。当我单击错误消息时,它将带我到PasswordManagerUITests项目的“构建阶段”部分。我在下面提供了该项目的错误截图和构建阶段。
import XCTest
@testable import PasswordManager
class ViewControllerTestCase: XCTestCase {
var viewController: ViewController!
override func setUp() {
super.setUp()
}
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() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
}
最佳答案
这是因为ViewController(这是PasswordManager中的类,对吗?)在UI测试级别上不可用。而且不应该这样。
UI测试中不需要@testable import PasswordManager
。在UI测试中,您仅测试UI元素(XCUIElement
对象),而不测试应用程序本身的类。
如果要测试您的应用程序类,则要编写单元测试而不是UI测试。
关于ios - clang:错误:链接器命令失败,退出代码为1(使用-v查看调用);从以下位置引用的“__TMaC15PasswordManager14ViewController”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44228247/