One of the most exciting things that’s come out of WWDC 2015 is the fact that unit testing in Swift has been greatly simplified. The latest announcements have actually rendered a few of my articles on the subject obsolete, once Xcode 7 is in full circulation among the Swift developer community.
If you’re using Xcode 6.x, you may still find use in a couple of my previous articles:
- Swift Access Control – Implications for Unit Testing
- Testability Tip for Swift Developers – Public Over Private
If you’re jumping headlong into Xcode 7 world, setting yourself up for unit testing is incredibly simple. Essentially, all
public Types (and members of those Types) are visible to your unit test project when you import the module using the
@testable keyword in front of the import. With Xcode 7, there’s no reason to change any of the access modifiers on your Types/members to support testing.
- Code your Types (classes/structs/enums) using the default
- Add an import statement to the file containing your
XCTestCases. There’s special syntax for this now:
@testable import AppName/ModuleName
- Begin unit testing with access to all
internalTypes and members!