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:
This didn't occur in my projects prior to Xcode 8, but after I upgraded to Xcode 8, it made me perplexed.
The answers posted here didn't get my problems resolved. For me, I just ditched these tests as it is not needed. So uncheck the test buttons:
And now the error has gone out.
For those of you who are experiencing this only upon running Xcode Profiler: switch profile build configuration in your scheme management to the one that has testability enabled - and that would be debug in most cases:
Make sure that you properly set your checkboxes under your app scheme. You SHOULD UNCHECK your test targets for Archive Build.
If you trying to test framework:
Go to test target -> Build Phase -> Create new copy files phase -> Choose frameworks -> Add all recursively used frameworks
This is probably because your main target Enable Testability
is set to NO
. You should set it to YES
in the debug scheme (which is used for running your tests).
If you use Carthage, this problem can be caused by importing frameworks with @testable
, because they are built with a release scheme.
Most of the times it's bad practice to import frameworks with that prefix, so you could avoid it.
If you can't, you should Enable Testability
in the frameworks' release scheme. https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW326
If by any chance you have
install! 'cocoapods',
generate_multiple_pod_projects: true,
incremental_installation: true
Then, this is the way to do it.
# generated_projects only returns results if the we run "pod install --clean-install"
# or install a pod for the first time
installer.generated_projects.each do |project|
project.build_configurations.each do |configuration|
configuration.build_settings["ENABLE_TESTABILITY"] = "YES"
end
end