Reputation: 4605
I created a Swift library with swift package init --type library
and generated an Xcode project with swift package generate-xcodeproj
.
Now I'm trying to run the Test scheme in Xcode. It prints following error:
Module '<title>' was not compiled for testing
However when I run swift build
and swift test
in terminal, it works fine.
I have ENABLE_TESTABILITY
set to YES
in all of the targets. I didn't change anything in the project except this. How can I make Xcode perform unit testing?
Upvotes: 12
Views: 6548
Reputation: 129
I had the same problem where Xcode would show the Module 'Foo' was not compiled for testing
, but I could still run the tests normally. The downside was that any code errors or warnings would not show up.
What solved this was to set Enable Testing Search Paths (ENABLE_TESTING_SEARCH_PATHS)
to Yes
.
Upvotes: 0
Reputation: 1
Xcode -> Product -> Scheme -> Edit Scheme
Select the Info tab.
Set the following - Build Configuration: Debug Add a check mark to Debug executable
Tested with Xcode 12.4(12D4e) and iOS 14.1 deployment target.
Upvotes: -1
Reputation: 147
You need to set the "Enable Testability" to Yes in build setting over your "Main Target"
Upvotes: 11
Reputation: 19702
I was having this issue today, it seems like @testable
cannot be used with projects generated by Swift Package Manager.
Removing @testable
from my import statements solved this issue. Of course, this means we can only test the public interface of our modules.
Upvotes: 4