3

How do you unit test a private class in Objective-C? Is it possible when both the @interface and the @implementation of the class are included in a .m implementation file?

Refactoring the interface of the private class into its own header is not allowed by the restrictions of the project.

This is a whole private class I would like to test, not a private method of a public class.

Community
  • 1
  • 1
hpique
  • 119,096
  • 131
  • 338
  • 476

1 Answers1

2

Apparently, duplicating the private interface in the test file is enough. Damn, Objective-C is dangerous!

hpique
  • 119,096
  • 131
  • 338
  • 476
  • If you are allowed, you could use a #define to make it possible to #import the .m. Something like #define INTERFACE_ONLY, then you use #ifdef to make the @implementation part not imported. – Lou Franco Sep 09 '13 at 23:07
  • Isn't it the same in C? (This is a genuine question, not a rhetorical one) – funct7 May 17 '18 at 02:00