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

我试着

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

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


当前回答

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

改变这一

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

这个

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

其他回答

XCode 12开发Beta 3

这个错误在我第一次构建项目后自行修复了。

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

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

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

在构建设置测试目标中,检查主机测试,它接受PRODUCT_NAME中设置的名称。 您应该在测试类中使用这个名称。

我建议不要更改PRODUCT_NAME(匹配主目标的名称)

我的解决方案在这里。

首先单击OdeAlSwiftUITest.swift,然后在目标成员中检查项目TargetName。

这是我在Xcode 13.1中使用的方法:

在Xcode Preferences > Locations的Locations选项卡中,我定义了一个自定义位置:

这不仅导致单元测试失败,出现可怕的“没有这样的模块”错误,而且还导致“命令CodeSign失败,退出码非零”和其他警告和错误。

将设置更改为唯一:

解决了所有问题。