Improvements to Unit Testing in Swift with Xcode 7

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:

If you’re jumping headlong into Xcode 7 world, setting yourself up for unit testing is incredibly simple. Essentially, all internal and 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.

@natashatherobot has an excellent 3-step write-up that I won’t repeat here. To summarize though, you’ll simply…

  • Code your Types (classes/structs/enums) using the default internal access.
  • 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 public and internal Types and members!
comments powered by Disqus