【发布时间】:2025-12-06 00:40:02
【问题描述】:
我正在编写 XCode 源编辑器扩展,我想添加一些测试以便我可以更快地开发。
我的设置是
MyContainerApplication
- SourceEditorExtension
- SourceEditorCommand.swift
- MyClass.swift
我想测试 MyClass.swift。 MyContainerApplication 对 SourceEditorExtension 有目标依赖。
所以我创建了将 MyContainerApplication 设置为主机应用程序的单元测试。
在我的测试中,我可以调用:
@testable import MyContainerApplication
class Test: XCTestCase {
func testSomething() {
let c = MyClass()
}
}
但是 XCode 说找不到 MyClass,这是有道理的,因为它没有包含在 HostApplication 中,而是包含在 SourceEditorExtension 中。我也打不通
@testable import SourceEditorExtension
因为它不是一个模块。
而且我无法将MyClass.swift 直接添加到我的测试目标或宿主应用程序目标,因为它使用XcodeKit 框架。我会得到一个错误:
XcodeKit module not found
看起来 XcodeKit 不能在 SourceEditorExtension 以外的任何地方导入,甚至在测试中也不能。
所以我的问题是 - 是否有其他方法可以测试源代码编辑器扩展?
【问题讨论】: