我最近更新到Xcode 7 beta 5。我尝试在早期的项目中添加一个单元测试,但是我在@可测试的导入myModuleName行上得到了错误消息“没有这样的模块[myModuleName]”。

我试着

使用“选项清理生成文件夹”清理项目 检查“启用可测试性”(调试)在构建选项中设置为“是” 删除测试目标,然后重新添加iOS单元测试包

这些都不适用于这个项目(但是我已经在另一个项目中进行了测试)。有人遇到过这个问题并解决了吗?


当前回答

这里还有一件没有列出的事情需要检查。对我来说,这与我的团队有关,也许是因为我们团队的经纪人还没有同意最新的许可协议!一旦我在目标的一般设置中选择了一个不同的团队,然后我指定了一个特定的部署目标,比如12.1或11.0,突然“没有这样的模块”警告消失了。

其他回答

CocoaPods推荐添加inherit!:search_paths到你的测试目标,就像这样:

target 'App' do
  target 'AppTests' do
    inherit! :search_paths
  end
end

来源:https://github.com/CocoaPods/CocoaPods/pull/8423问题——244992565

XCode 12.6 测试版

我不确定是什么导致了这个问题,但清洁我的构建文件夹没有排序。重启XCode也没有解决这个问题。

对我有效的方法是删除这一行:import XCTest,然后重新输入它。

这里还有一件没有列出的事情需要检查。对我来说,这与我的团队有关,也许是因为我们团队的经纪人还没有同意最新的许可协议!一旦我在目标的一般设置中选择了一个不同的团队,然后我指定了一个特定的部署目标,比如12.1或11.0,突然“没有这样的模块”警告消失了。

因此,在尝试了之前建议的所有解决方案后,这就是我如何让我的代码工作的。

I set 'Enable testability' to 'YES' in project's Build Settings I also set 'Defines Module' to 'YES' in my project's Build Settings. For the regular .swift file(s) within my project, say MyApp, I was going to write test cases for, I have both the main "MyApp" and the "MyAppUnitTests" Targets checked under Target Membership. I then selected my unit test file(s), declared the '@testable import MyApp' at the top, beneath the 'import XCTest', and only checked the "MyAppUnitTests" under Target membership

一切都很顺利。希望这能有所帮助。

如果您正在使用xcodebuild并发现此问题,请考虑在build命令中添加一个工作区标志。

改变这一

$ xcodebuild -scheme PowToonsTests -destination 'name=iPhone X' test

这个

$ xcodebuild -workspace PowToons.xcworkspace -scheme PowToonsTests -destination 'name=iPhone X' test