Question

I have a UIViewController and I have been trying to unit test it. I have some private variables, and methods. I would like them to stay private. The question is, should I actually test private interface? Does it matter how it does internally, as long as it does what it is supposed to from the 'outside' point of view?

Would tests be difficult to understand/maintain/modify if I start testing private interface? Would that be a significant limiting factor when it comes to the ease changing the internal implementation. Private methods/properties are not mentioned the header file, therefore, if someone else comes along, the person would have to peak into the private interface.

Also, should I test the interaction between UIViewController & UIView ?

Was it helpful?

Solution

Don't test private implementation, because that ties your implementation down. It leads to fragile tests.

You may feel a need to test something internal. That's a good indication that it need to be made public in some way. It could indicate that there's another class inside trying to get out. You can extract it and test it, then trust that it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top