1

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.

  • Basically, [you don't](https://stackoverflow.com/a/105021/3141234). – Alexander Feb 19 '18 at 19:47
  • 2
    Why would you want to test someone else's code? If you don't trust the library, then don't use it. Good libraries are well tested. – Cristik Feb 19 '18 at 19:51
  • You should test everything within the private library itself not from the consumer of the library (the app using cocoapods to manage the library) – Paul.s Feb 19 '18 at 21:04
  • 1
    @Paul.s Sorry maybe this isn't worded clearly, I am creating a CocoaPod Library myself and I want to test the source code that I am writing – Andy Meagher Feb 19 '18 at 22:41
  • 1
    @Cristik I am trying to test the source code of the library I am writing, not some else's code. – Andy Meagher Feb 19 '18 at 22:44
  • 2
    @AndyMeagher my original comment stands. If you write `FrameworkA` that you then import into you `App`. You should test `FrameworkA`'s code from within `FrameworkA` not the `App`. – Paul.s Feb 19 '18 at 23:52
  • @AndyMeagher you don't need to test non-public stuff, check [this answer](https://stackoverflow.com/a/37421807/1974224) from more details – Cristik Feb 20 '18 at 05:56

1 Answers1

1

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

Hogdotmac
  • 282
  • 6
  • 7