用Swift写单元测试,需要在测试类中引入主Target模块
1 | import Normandy |
在Swift 1、1.2中,虽然这样做了,但还是无法使用主工程中的internal类,若想测试某些类,必须把它们写成public的,并且要添加到单元测试的Target中。
在Swift 2 + Xcode 7中,引入了关键字@testable
现只需要两步:
第一步:

在主工程的Target的Build Settings中把Enable Testability设置为YES
第二步:
1 | @testable import Normandy |
引入主工程时加上@testable关键字作为前缀
现在即可在测试类中引入任何主工程中的internal类了。