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

后端 未结 30 1369
春和景丽
春和景丽 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:37

    My solution is here.

    Firstly OdeAlSwiftUITest.swift click, then check Project TargetName in target membership.

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

    After spending couple of days on this issues finally I make it to work with my project. Problem was in Bridging Header - path in Tests target can't be empty if you are using Bridging Header in your main target

    Hope it will save some time for someone.

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

    In my case , I had 3 issues. The first was that I had to specify the import path in :

    Target -> Build Settings -> Swift Compiler - Search Paths -> Import Paths
    

    The second was that I was using Pods and I had to import these pods to my tests as well using :

    target 'MyAppTests' do
        inherit! :complete
    end
    

    The third one as that I was using a bridging header in my target , thus I had to specify the bridging header to be the same for the test.

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

    One gotcha to watch for is that if your module name has a dash character in it - then you will have to refer to it with an underbar instead _. For some reason I suspected this might be an issue and it was indeed my issue.

    eg. @testable import Ocean-Swift becomes @testable import Ocean_Swift

    Just one other thing, if you do use the @testable syntax be sure to not include your production code in your test target. I've found this will cause inexplicable weirdness.

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

    For those who have scrolled until the last answer and still nothing worked, here is what did it for me after following all other answers advices. I am using Xcode 11:

    What caused the issue in my case was that I changed my Product Name

    1. I changed my Product Name in the Build Settings of my main target to "New Name"
    2. I had to re-select the Host Application for my test target
    3. I didn't know that changing the product name would also change the Product Module Name, that is the one used for the module import in my test files. I changed my import as follows:

      @testable import New_Name

    4. It worked

    I hope it helps

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

    I think this may have happened because I deleted the example tests.

    I removed the Unit test bundle then re-added it as shown in the pictures below and all was well again.

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