Daily iOS
Testing

Writing testable code

The question asks about your experience writing code with unit tests in mind and the philosophy you took from it. Give me the principles you hold to as concrete code-level habits.

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

Take dependencies through the initializer and don't call singletons directly. Pull decision logic into pure functions from input to output and push side effects to the edges. Inject time, UUID, and randomness, and express state as a value type so it's comparable. Treat "this is hard to test" as a design signal and change the code.

Share a question