Andy Meagher
Andy Meagher

Reputation: 21

How do you unit test internal methods of a CocoaPod Library?

I have a private iOS Library that I want to use CocoaPods to manage. However, I can't wrap my head around how to unit test the internal methods of the library. I used pod lib create to set up my file structure, and this creates Tests that point to the 'Example' project, and therefore only have access to methods from my library that I expose as 'Open'. How can I unit test the internal methods that are not 'Open'? Obviously any Test Target I create under the Source Files gets erased once I do pod install...Why doesn't pod lib create make it easier to actually test your source code instead of just its exposed functionality?

This github issue addresses my exact problem, but I still don't quite understand the resolution: https://github.com/CocoaPods/CocoaPods/issues/4755

Any help is greatly appreciated!

EDIT

I think i figured out what I was struggling with. By using the @testable import of the pod module I am able to test 'Public' methods. Initially I thought I had to make them 'Open' but the keyword @testable solves this for me.

Upvotes: 1

Views: 1098

Answers (1)

Hogdotmac
Hogdotmac

Reputation: 347

for reference, the solution is: use @testable import

check out: https://medium.com/practical-ios-development/how-to-write-unit-tests-in-swift-without-making-everything-public-ae218acc4ec4

Upvotes: 1

Related Questions