0

I have a plist file that contains a top level dictionary and that dictionary contains an array of strings.

I want to test:

  1. That the dictionary is not nil
  2. That the array is not nil
  3. And that the array has at least one valid string object in it

I have these unit tests running great. Very de-coupled. But the problem is I have to make the class functions public in order for Xcode XCTest to be able to test them. These 3 functions are simply helper functions to get the actual data we need.

How do I employ proper visibility on these helper functions while keeping my tests? No one needs to know about these 3 functions, but I want them tested.

Spentak
  • 3,359
  • 3
  • 21
  • 31
  • Are you sure you should? See the second answer here: http://stackoverflow.com/questions/250692/how-do-you-unit-test-private-methods – Alex Wayne Sep 09 '14 at 22:58
  • I see what you are saying - test only the public API. But what about when I want to test if a Plist exists? Maybe someone accidentally deleted it from the project. If so I would immediately know what the problem is. This isn't a public api function but still needs to be tested (I think). What do you think? – Spentak Sep 09 '14 at 23:03

1 Answers1

1

There are two solid options for this:

  1. Create a second .h file named something like MyClass_TestHelpers.h where you can declare those methods you need.
  2. Create a category on the class titled something like 'TestHelpers'.

Both do essentially the same thing: declare methods in another .h file. In either case, just include that .h file in the test class. This way the methods are only exposed to your tests.

AdamPro13
  • 7,232
  • 2
  • 30
  • 28