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

hgwhittle picture hgwhittle · Jun 11, 2015 · Viewed 28.7k times · Source

I'm trying to use Swift 2's new @testable declaration to expose my classes to the test target. However I'm getting this compiler error:

enter image description here

Intervals is the module that contains the classes I'm trying to expose. How do I get rid of this error?

Answer

sgaw picture sgaw · Jun 11, 2015

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