What happens behind the scenes in XCTest @testable?

I know that

@testable import MyModule

allows you to examine non-public members MyModulefrom the "test" module (built using the "testTarget") MyModuleTests.

I need the same functionality in my non-test module. Not in production, only in debug mode.

My question is: do you know how to do this?

And related (I think a more complicated question): what kind of magic really happens for @testable?

+4
source share
1 answer

To answer your question, you can really use this for debugging purposes. Say you have a workspace MyAwesomeWkspaceand a project inside MyAwesomeProject.

framework aka module, MyAwesomeModule. Person.

Person MyAwesomeProject, import MyAwesomeModule, - let p = Person(), .

@testable import MyAwesomeModule, , .

@testable , . import, .

, , -enable-testing, . ,

debug -enable-testing, , , . release, Module .. was not compiled for testing, config release .

Swift, Access Control " " (Swift 4), -, . , , , , Swift.

Xcode :

" " "", true , Xcode -enable-test flag . , Swift, , . @testable , , . , , . , .

: - . , "", : https://github.com/apple/swift

+13

Source: https://habr.com/ru/post/1687675/


All Articles