“No such module” when using @testable in Xcode Unit tests

后端 未结 30 1373
春和景丽
春和景丽 2020-12-02 05:33

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 @te

相关标签:
30条回答
  • 2020-12-02 05:46

    This sounds to be an error with the build settings of both targets. You need to ensure that:

    • ENABLE_TESTABILITY equals Yes for both targets.
    • The PRODUCT_MODULE_NAME value of the test target should differ from the one of the application.
    0 讨论(0)
  • 2020-12-02 05:46

    In build settings test target, check the host testing, it takes the name set in PRODUCT_NAME. It is that name that you should use in test classes.

    I recommand to not change PRODUCT_NAME (match name of the main target)

    0 讨论(0)
  • 2020-12-02 05:47

    Environment: Xcode Version 9.0 (9A235)
    Scenario: Testing an open-source framework.

    I had the same problem: 'No such module'.

    Solution:

    1. Select the Test target.
    2. Select Build Phases
    3. Add the framework to be tested via Link Binary...

    Here's the test file:

    0 讨论(0)
  • 2020-12-02 05:47

    I had this same issue. Cleaning the build folder and restarting Xcode did not work.

    What did work for me was ensuring that the setting for "Build Active Architecture Only" of your test target and scheme matches the setting of your app's target and scheme.

    0 讨论(0)
  • 2020-12-02 05:47

    I tried all the answers here but the red flag would not go away. But I got it to work by just "running" an empty test regardless and it cleared up.

    Things I would like make sure are done:

    • Host Application
    • @testable import "Module_name" (make sure the module name is correct)
    • Make sure you deployment target for the test is the same as the project
    • XCTest does not need to have Target membership
    0 讨论(0)
  • 2020-12-02 05:48

    I followed the steps above, which worked. However, my project had some more issues. I got this warning and I could not access classes from my main project to test in my test target.

    I found that your Test target Product Module Name (YourTestTarget -> Build Settings -> search for product module) cannot be the same name as your project name.

    Once I changed the Product Module Name for my test target everything worked.

    0 讨论(0)
提交回复
热议问题