objective-ccocoaxcodetddocunit

Unit Testing of private methods in Xcode


I'm trying out test driven development in a toy project. I can get the tests working for the public interface to my classes (although I'm still on the fence because I'm writing more testing code than there is in the methods being tested).

I tend to use a lot of private methods becuase I like to keep the public interfaces clean; however, I'd still like to use tests on these methods.

Since Cocoa is a dynamic language, I can still call these private methods, but i get warnings in my tests that my class may not respond to these methods (although it clearly does). Since I like to compile with no warnings here are my questions:

  1. How do i turn off these warnings in Xcode?
  2. Is there something else I could do to turn off these warnings?
  3. Am I doing something wrong in trying 'white box' testing?

Solution

  • How do i turn off these warnings in Xcode?

    Don't.

    Is there something else I could do to turn off these warnings?

    Don't.

    Am I doing something wrong in trying 'white box' testing?

    No.

    The solution is to move your private methods to a category in its own header. Import this header into both the real class and test-case class implementation files.