首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于多平台应用程序的Swift UnitTest未定义符号

用于多平台应用程序的Swift UnitTest未定义符号
EN

Stack Overflow用户
提问于 2022-08-24 14:44:51
回答 1查看 87关注 0票数 -1

我尝试用xcode 13.4.1创建单元测试

我创建了一个新的projet,让我们称它为MyApp,包括单元测试。

File -> New -> Project -> Multiplatform -> App

我为示例创建了一个简单的类

代码语言:javascript
复制
class Manager {
    
    var customData: CustomData
    
    init(custom: CustomData) {
        customData = custom
    }
    
    func setName(value: String) {
        customData.name = value
    }
}

有一个简单的数据结构

代码语言:javascript
复制
struct CustomData {
    var name: String
}

然后我创建了一个XCTestCase

代码语言:javascript
复制
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")
    }
}

但我有个问题:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2022-08-24 21:06:09

由于这个应用程序是用于多平台的,我在这里找到了一个解析器:https://developer.apple.com/forums/thread/665120

默认测试是UI,您需要添加一个单元测试目标,然后创建一个新的构建方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73475184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档