我尝试用xcode 13.4.1创建单元测试
我创建了一个新的projet,让我们称它为MyApp,包括单元测试。
File -> New -> Project -> Multiplatform -> App
我为示例创建了一个简单的类
class Manager {
var customData: CustomData
init(custom: CustomData) {
customData = custom
}
func setName(value: String) {
customData.name = value
}
}有一个简单的数据结构
struct CustomData {
var name: String
}然后我创建了一个XCTestCase
import XCTest
@testable import MyApp
class Tests_iOS: XCTestCase {
var manager: Manager = Manager(custom: .init(name: "Hello"))
func testManagerChangeNameChange() {
XCTAssert(manager.customData.name == "Hello")
manager.setName(value: "Bonjour")
XCTAssert(manager.customData.name == "Bonjour")
}
}但我有个问题:
Undefined symbol: nominal type descriptor for MyApp.Manager
Undefined symbol: type metadata accessor for MyApp.Manager
Undefined symbol: MyApp.CustomData.init(name: Swift.String) -> MyApp.CustomData
Undefined symbol: MyApp.Manager.__allocating_init(custom: MyApp.CustomData) -> MyApp.Manager
Undefined symbols for architecture x86_64:
"nominal type descriptor for MyApp.Manager", referenced from:
_symbolic _____ 5MyApp7ManagerC in Tests_iOS.o
"type metadata accessor for MyApp.Manager", referenced from:
variable initialization expression of Tests_iOS.Tests_iOS.manager : MyApp.Manager in Tests_iOS.o
Tests_iOS.Tests_iOS.init(invocation: __C.NSInvocation?) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init(selector: ObjectiveC.Selector) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init() -> Tests_iOS.Tests_iOS in Tests_iOS.o
"MyApp.CustomData.init(name: Swift.String) -> MyApp.CustomData", referenced from:
variable initialization expression of Tests_iOS.Tests_iOS.manager : MyApp.Manager in Tests_iOS.o
Tests_iOS.Tests_iOS.init(invocation: __C.NSInvocation?) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init(selector: ObjectiveC.Selector) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init() -> Tests_iOS.Tests_iOS in Tests_iOS.o
"MyApp.Manager.__allocating_init(custom: MyApp.CustomData) -> MyApp.Manager", referenced from:
variable initialization expression of Tests_iOS.Tests_iOS.manager : MyApp.Manager in Tests_iOS.o
Tests_iOS.Tests_iOS.init(invocation: __C.NSInvocation?) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init(selector: ObjectiveC.Selector) -> Tests_iOS.Tests_iOS in Tests_iOS.o
Tests_iOS.Tests_iOS.init() -> Tests_iOS.Tests_iOS in Tests_iOS.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)发布于 2022-08-24 21:06:09
由于这个应用程序是用于多平台的,我在这里找到了一个解析器:https://developer.apple.com/forums/thread/665120
默认测试是UI,您需要添加一个单元测试目标,然后创建一个新的构建方案。
https://stackoverflow.com/questions/73475184
复制相似问题