[swift-evolution] [Pitch] @testable private members

Brent Royal-Gordon brent at architechies.com
Sun Feb 19 00:21:33 CST 2017

> On Feb 18, 2017, at 10:14 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
> When writing unit tests sometimes it is necessary to artificially elevate a member to `internal` in order to make it visible to unit tests where it could otherwise be `private` or `fileprivate`.  We could introduce an `@testable` attribute that could be applied anywhere an access modifier is used.  This attribute would elevate the access modifier to `internal` when the module is imported using the `@testable import MyModule` syntax in a test suite.

	extension MyModel {
		public func load(fromJSON jsonData: Data) throws {
		private func parse(_ json: Data) -> Any { … }
	extension MyModel {
		public func load(fromPropertyList plistData: Data) throws {
		private func parse(_ plist: Data) -> Any { … }

What happens when you try to test `MyModel.parse(_:)`?

Brent Royal-Gordon

More information about the swift-evolution mailing list