我最近更新到Xcode 7 beta 5。我尝试在早期的项目中添加一个单元测试,但是我在@可测试的导入myModuleName行上得到了错误消息“没有这样的模块[myModuleName]”。
我试着
使用“选项清理生成文件夹”清理项目 检查“启用可测试性”(调试)在构建选项中设置为“是” 删除测试目标,然后重新添加iOS单元测试包
这些都不适用于这个项目(但是我已经在另一个项目中进行了测试)。有人遇到过这个问题并解决了吗?
我最近更新到Xcode 7 beta 5。我尝试在早期的项目中添加一个单元测试,但是我在@可测试的导入myModuleName行上得到了错误消息“没有这样的模块[myModuleName]”。
我试着
使用“选项清理生成文件夹”清理项目 检查“启用可测试性”(调试)在构建选项中设置为“是” 删除测试目标,然后重新添加iOS单元测试包
这些都不适用于这个项目(但是我已经在另一个项目中进行了测试)。有人遇到过这个问题并解决了吗?
当前回答
因此,在尝试了之前建议的所有解决方案后,这就是我如何让我的代码工作的。
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
一切都很顺利。希望这能有所帮助。
其他回答
对我来说,问题是测试的iOS部署目标没有设置为与主目标相同。所以一定要检查这个。
在您的测试目标中:
Build Settings -> iOS Deployment Target -> iOS<same as the target you are testing>
这是我在Xcode 13.1中使用的方法:
在Xcode Preferences > Locations的Locations选项卡中,我定义了一个自定义位置:
这不仅导致单元测试失败,出现可怕的“没有这样的模块”错误,而且还导致“命令CodeSign失败,退出码非零”和其他警告和错误。
将设置更改为唯一:
解决了所有问题。
因此,在尝试了之前建议的所有解决方案后,这就是我如何让我的代码工作的。
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
一切都很顺利。希望这能有所帮助。
XCode 12开发Beta 3
这个错误在我第一次构建项目后自行修复了。
对我来说,解决办法就是重新命名 导入myproject_ios 来 导入myproject 在我更新了目标myproject-ios的产品名称在构建设置/包装/产品名称/从${TARGET_NAME}到myproject。