July 6th, 2015
A new feature added in Xcode 7 to simplify unit testing is the
@testable import statement. Instead of making your application classes members of the unit testing target, which is what you had to do to unit test Swift code in Xcode 6, add the following statement to your unit testing classes:
@testable import MyApp
MyApp is the name of your application target.
If you get link errors when running your tests, make sure the value of the Product Module Name build setting matches the module name in the
@testable import statement. In my example that would be
I was getting link errors in my project because my project name has a space in it so Xcode was using
My_App as the module name in the Product Module Name build setting.
My_App is not the same as
MyApp, causing the link error. Changing the Product Module Name to
MyApp fixed the link error.