I feel it prudent to attempt to master Unit Testing/Swift.
I viewed WWDC's Objective-C version and pretty much understand the Objective-C paradigm: importing the headers that the Unit Test depends on, etc.
The 'fetchFlickrPhotoWithSearch()' is unknown to the Unit Test. So...
Being that a Unit Test module/target is outside the scope of the application target, I assume that I need to import the particular Swift file (similar to Objective-C's header paradigm) that has the functions I wish to test.
But the compiler flags this import as 'No such module...'
So... how do I make my Swift APIs available to the unit test?
The solution recommended by Steve Rosenberg is an easy one but leads to issues that are hard to debug (an instance of which is documented here if you're interested).
The recommended approach is to edit your app target's (not the test target) Build Settings and set "Defines Module" under Packaging to YES.
With that done, in your test target, at the top of each .swift file, import your projects main module to get access to your classes, structs, etc. The name of the main module is typically the same name as your Xcode project file.
Note: When following this approach, you will have to annotate all class/struct/enum methods that you want to test with the public access control modifier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With