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

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

    So this is how I went about getting my code to work after trying all suggested solutions from prior suggestions.

    • I set 'Enable testability' to 'YES' in project's Build Settings
    • I also set 'Defines Module' to 'YES' in my project's Build Settings.
    • For the regular .swift file(s) within my project, say MyApp, I was going to write test cases for, I have both the main "MyApp" and the "MyAppUnitTests" Targets checked under Target Membership.
    • I then selected my unit test file(s), declared the '@testable import MyApp' at the top, beneath the 'import XCTest', and only checked the "MyAppUnitTests" under Target membership

    And everything worked like charm. Hope this helps.

提交回复
热议问题