'Module was not compiled for testing' when using @testable 'Module was not compiled for testing' when using @testable ios ios

'Module was not compiled for testing' when using @testable


In your main target you need to set the Enable Testability build option to Yes.

As per the comment by @earnshavian below, this should only be used on debug builds as per apple release notes: "The Enable Testability build setting should be used only in your Debug configuration, because it prohibits optimizations that depend on not exporting internal symbols from the app or framework" https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW326


In my case I used a custom build configuration for testing (called Test) and also cocoapods as a dependency manager

I had to add the following lines to the end of my Podfile to enable testability

post_install do |installer|    installer.pods_project.targets.each do |target|        target.build_configurations.each do |config|            if config.name == 'Test'                config.build_settings['ENABLE_TESTABILITY'] = 'YES'            end        end    endend

By default cocoapods sets ENABLE_TESTABILITY to YES only for Debug builds


Make sure that you properly set your checkboxes under your app scheme. You SHOULD UNCHECK your test targets for Archive Build.

enter image description here