Daily iOS
Testing

Testing private methods

A private method inside a custom view holds complicated calculation logic and you want to test it. How would you test that private method, or should you leave it alone?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Don't try to test private itself: verify it through the public behavior, or extract it into its own type if the logic is worth testing. Internal plus @testable import is a workable compromise, but calculation logic living inside a view is a design signal in itself.

Share a question