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

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

    For me the solution was to rename @testable import myproject_ios to @testable import myproject after I had updated product name of target myproject-ios in Build Settings/Packaging/Product Name/ from ${TARGET_NAME} to myproject.

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

    Here is yet another thing to check that is not listed. For me, it had something to do with my team, perhaps because our Team's Agent had not yet agreed to the latest License Agreement! Once I selected a different Team in my Target's General settings, AND then I specified a specific Deployment Target like 12.1 or 11.0, suddenly the "No Such Module" warning went away.

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

    CocoaPods recommends adding inherit! :search_paths to your test target like so:

    target 'App' do
      target 'AppTests' do
        inherit! :search_paths
      end
    end
    

    Source: https://github.com/CocoaPods/CocoaPods/pull/8423#issue-244992565

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

    If you have some targets in your project - check your TARGETS in Module Name that you try to import with @testable import "TARGETSModuleName".

    The module name should be the same on: Target -> Build Settings -> Product Module Name

    For example:

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

    XCode 12.6 beta

    I'm not sure what caused this issue for me but cleaning my build folder didn't sort it. Restarting XCode didn't sort out the issue either.

    What worked for me was deleting this line: import XCTest, and then retyping it again.

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

    If you are using xcodebuild and find this problem, consider adding in a workspace flag to the build command.

    Changed This

    $ xcodebuild -scheme PowToonsTests -destination 'name=iPhone X' test
    

    To This

    $ xcodebuild -workspace PowToons.xcworkspace -scheme PowToonsTests -destination 'name=iPhone X' test
    
    0 讨论(0)
提交回复
热议问题