ios - Add a type function to a Swift unit test target -
how 1 go making type function (defined in extension) visible test target in swift? if have following extension in project:
extension nsdata { class func xor(inputdata: nsdata, withkey key: nsdata) -> nsdata { ... return nsdata(bytes: output.baseaddress, length: inputdata.length) } }
the xor
function visible the main project not in test target. have @testable import mymodule
in test file. (as aside, interestingly variables added in extension visible test target).
there 3 ways (that can recall) of making function visible within test target.
- add test target target membership of file containing extension.
- promote function
internal
(which implicitly set omitting access modifier)public
. - upgrade xcode 7 beta , use swift 2's new
@testable
attribute import module. doing implicitly promoteinternal
variables/methods/etcpublic
make them visible within tests target.
@testable import mymodule
Comments
Post a Comment