Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Module was not compiled for testing" error when using Swift Package Manager

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?

like image 439
egor.zhdan Avatar asked Feb 18 '17 14:02

egor.zhdan


2 Answers

You need to set the "Enable Testability" to Yes in build setting over your "Main Target"

enter image description here

like image 112
Sudhir Bhagat Avatar answered Nov 04 '22 17:11

Sudhir Bhagat


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.

like image 39
Eneko Alonso Avatar answered Nov 04 '22 18:11

Eneko Alonso