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.

7
  • Basically, you don't. Commented Feb 19, 2018 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. Commented Feb 19, 2018 at 19:51
  • 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 Commented Feb 19, 2018 at 22:41
  • 1
    @Cristik I am trying to test the source code of the library I am writing, not some else's code. Commented Feb 19, 2018 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. Commented Feb 19, 2018 at 23:52

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.