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

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

问题描述

我最近更新到Xcode 7 beta 5.我尝试将单元测试添加到早期项目中,但是我在 @testable import myModuleName上收到错误消息No such module [myModuleName] line。





我试过




  • 使用选项清理构建文件夹清理项目

  • 检查启用可测试性 (调试)在构建选项中设置为是

  • 删除测试目标,然后重新添加iOS单元测试包



这个项目都没有用(但我已经开始测试在另一个项目中工作)。有其他人有这个问题并解决了吗?

解决方案

对我有用的答案



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



请注意,这些错误并非如此t首先出现。要让它们出现:




  • 注释掉整个测试文件,它会给你没有这样的模块错误。

  • 尝试再次运行您的项目。



如果还有其他错误,它们现在应该出现。修复它们,然后取消注释Test文件代码。 没有这样的模块错误消失了。






如果这不能解决其他人的问题,您还可以尝试以下方法:



清理构建文件夹



打开在产品菜单中,按住选项,然后单击清除构建文件夹...





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



如果您已完成其他操作,我猜您可能不需要去做这个。但如果你这样做,



然后单击加号(+)按钮并选择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天全站免登陆