ylliX - Online Advertising Network Testing with Swift 2.x - Yet Another Programmer's Blog

Testing with Swift 2.x

Testing is good practice, but sometimes you may get into trap. Opposite to Objective-C, in Swift 2.x you don’t need to add each file to your test target, even more – you should not do this at all!

Using Swift 1.x developers had to make every testable class and methods public, which was very annoying. Now, all you have to do, is use:

@testable import ProjectName

in each of your test files (this is required for both unit testing and UI testing). But there is one catch – what if your project name contains spaces like “My First Swift Project”? Fortunately there is simple solution, in most cases just replace space with underscore, but if you want to be sure, go to your app’s target, then “Build settings”, and search for “Module name” – this is string you should use in import.

Swift unit/UI testing

Leave a Reply