“没有这样的模块"在 Xcode 单元测试中使用 @testable 时 [英] "No such module" when using @testable in Xcode Unit tests

查看:26
本文介绍了“没有这样的模块"在 Xcode 单元测试中使用 @testable 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到 Xcode 7 beta 5.我尝试向早期项目添加单元测试,但在 @testable import myModuleName 线.

我试过了

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

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

解决方案

对我有用的答案

答案是我的项目中有一些错误导致构建失败.(这只是代码中每天的标准错误.)在我修复了错误并进行了另一次清理和构建之后,它起作用了.

请注意,这些错误最初并未出现.让他们出现:

  • 注释掉出现没有此类模块"错误的整个测试文件.
  • 尝试再次运行您的项目.

如果还有其他错误,它们现在应该会出现.修复它们,然后取消注释您的测试文件代码.没有这样的模块"错误对我来说消失了.

<小时>

如果这不能解决其他人的问题,您也可以尝试以下操作:

清理构建文件夹

打开产品菜单,按住Option,然后点击Clean Build Folder..."

确保启用可测试性设置为是

在项目导航器中单击您的项目名称.选择构建设置并向下滚动到构建选项.确保启用可测试性为是(用于调试).

删除并重新添加您的测试目标

如果您已经完成了其他事情,我的猜测是您可能不需要这样做.但是如果你这样做了,

然后单击加号 (+) 按钮并选择 iOS Unit Testing Bundle 将其重新添加回来.如您所见,您还可以以相同的方式添加 UI 测试包.

其他一些想法

  • 确保所有必需的类都是测试目标的成员.
  • 确保您已添加所有必需的库.
  • 确保模块名称写入正确(请参阅此答案).

或者...

如果您发现其他有用的方法,请在下方发表评论或回答.

相关

I recently updated to Xcode 7 beta 5. I tried adding a unit test to an earlier project, but I am getting the error message "No such module [myModuleName]" on the @testable import myModuleName line.

I tried

  • cleaning the project with Option Clean Build Folder
  • checking that "Enable Testability" (debug) was set to Yes in the Build Options
  • deleting the tests target and then re-adding the iOS Unit testing bundle

None of this worked for this project (but I have gotten testing to work in another project). Has anyone else had this problem and solved it?

解决方案

The answer that worked for me

The answer was that I had some errors in my project that was making the build fail. (It was just your standard every day bug in the code.) After I fixed the errors and did another clean and build, it worked.

Note that these errors didn't show up at first. To get them to show up:

  • Comment out your entire Test file that is giving you the "No such module" error.
  • Try to run your project again.

If there are other errors, they should show up now. Fix them and then uncomment your Test file code. The "No such module" error was gone for me.


In case this doesn't solve the problem for other people, you can also try the following:

Clean the build folder

Open the Product menu, hold down Option, and click "Clean Build Folder..."

Make sure that Enable Testability is set to Yes

In the Project Navigator click your project name. Select Build Settings and scroll down to Build Options. Make sure that Enable Testability is Yes (for debug).

Delete and re-add your Tests target

If you have done the other things my guess is that you probably don't need to do this. But if you do, remember to save any Unit Tests that you have already written.

Click your project name in the Project Navigator. Then select your Tests target. Click the minus (-) button at the bottom to delete it.

Then click the plus (+) button and choose iOS Unit Testing Bundle to add it back again. As you can see, you can also add a UI Testing Bundle in the same way.

A few other ideas

  • Make sure that all required classes are members of your test target.
  • Make sure that you have added all the required libraries.
  • Make sure that the module name is written correctly (see this answer).

Or...

Leave a comment or answer below if you found something else that worked.

Related

这篇关于“没有这样的模块"在 Xcode 单元测试中使用 @testable 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆