How to configure Unit Test for Swift?

I find it wise to try to master Unit Testing / Swift.
I reviewed the WWDC version of Objective-C and pretty much understand the Objective-C paradigm: importing the headers that Unit Test depends on, etc.

"FetchFlickrPhotoWithSearch ()" unknown Unit Test. So...

Since the Unit Test module / target is outside the scope of the application, I assume that I need to import a specific Swift file (similar to the Objective-C header paradigm) that has functions that I want to test.

But the compiler marks this import as "There is no such module ..."

So ... how do I make my Swift API available for unit test?

enter image description here

+5
unit-testing swift
Sep 30 '14 at 18:58
source share
2 answers

There is a good idea here:

http://natashatherobot.com/swift-unit-testing-tips-and-tricks/

Make sure that the class file you want to test has the target membership checked for tests in the Identity inspector file in the utilities panel. This caught me for the first time.

0
Sep 30 '14 at 19:25
source share

The solution recommended by Steve Rosenberg is simple, but leads to problems that are difficult to debug (a copy of which is documented here if you're interested).

The recommended approach is to edit the purpose of your application (not the target audience) and configure "Define module" in the "Packaging" section YES .

At the same time, in the test target at the top of each .swift file, import the main module of your projects to gain access to your classes, structures, etc. The name of the main module usually matches the name of your Xcode project file.

Note When implementing this approach, you will need to annotate all the class / struct / enum methods that you want to test using the public access control modifier.

+8
Apr 03 '15 at 16:15
source share



All Articles