Joey Yi Zhao
Joey Yi Zhao

Reputation: 42418

How to let unit test to access app's target classes in swift

I am using swift2 on an iphone application. When I tried to create some unit tests, it complains not found the classes from my app's target. I did some search and found a solution to add all the classes from app's target to the test target's Compile Sources. But I don't think this is a good way to solve this issue for that I have to add the file whenever I create a new one. Is there another solution for this?

Upvotes: 3

Views: 784

Answers (1)

Stefan Salatic
Stefan Salatic

Reputation: 4513

Just add @testable before import in you Unit tests. Then you will have access to everything like you would in Objective-C.

Like this

@testable import MyModule 

You can check out this tutorial on how to test in Swift 2 https://www.natashatherobot.com/swift-2-xcode-7-unit-testing-access/

Upvotes: 3

Related Questions