无法在测试框架中使用XCTUnwrap。

huangapple go评论70阅读模式
英文:

Not able to use XCTUnwrap in Test Framework

问题

我正在尝试创建一个包括一些扩展的测试框架。我能够按照这里的建议在框架中导入 XCTest:https://stackoverflow.com/a/35102636/3475906

但是,每当我尝试使用 XCTUnwrap 时,我都会收到错误消息:“未解析的标识符 'XCTUnwrap'”

基本上,我想要类似于这样的东西:

import XCTest

extension Optional {
    func unwrap() -> Wrapped {
        do {
            return try XCTUnwrap(self)
        } catch {
            print("处理错误")
        }
    }
}

有人有任何想法吗?

英文:

I am trying to create a test Framework that includes some extensions. I am able to import XCTest in the framework by following the suggestions from here: https://stackoverflow.com/a/35102636/3475906

However, whenever I try to use XCTUnwrap I got error: Use of unresolved identifier 'XCTUnwrap'

Basically, I want something like this:

import XCTest

extension Optional {
    func unwrap() -> Wrapped {
        do {
            return try XCTUnwrap(self)
        } catch {
            print("Handle error")
        }
    }
}

Does anybody have any idea?

答案1

得分: 5

XCTUnwrap API 仅在主要测试捆绑目标中可用,而不在其他库或框架中可用。有两种方法可以解决此问题:

  1. 将您的 Optional 扩展移到主捆绑中,这显然不是您想要做的 无法在测试框架中使用XCTUnwrap。
  2. 修改您的测试框架目标中的以下构建设置:
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
    "$(inherited)",
    "$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
    "$(inherited)",
    "$(PLATFORM_DIR)/Developer/usr/lib",
);
SWIFT_INCLUDE_PATHS = "$(inherited) $(PLATFORM_DIR)/Developer/usr/lib"
英文:

The XCTUnwrap API is only available in primary test bundle targets and not in other libraries or frameworks. There are two ways to fix this issue:

  1. Move your Optional extension to the main bundle which obviously not something you want to do 无法在测试框架中使用XCTUnwrap。
  2. Modify the following build settings in your test framework target:
SYSTEM_FRAMEWORK_SEARCH_PATHS = (
	"$(inherited)",
	"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
	"$(inherited)",
	"$(PLATFORM_DIR)/Developer/usr/lib",
);
SWIFT_INCLUDE_PATHS = "$(inherited) $(PLATFORM_DIR)/Developer/usr/lib"

答案2

得分: 0

在至少 Xcode 11.4 版本中,您可以在项目或目标的“构建设置”中启用:

ENABLE_TESTING_SEARCH_PATHS = YES

英文:

At least since Xcode 11.4 you may just enable:

ENABLE_TESTING_SEARCH_PATHS = YES

in the "Build Settings" of your project or target.

huangapple
  • 本文由 发表于 2020年1月6日 22:41:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614017.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定