SpinTheMic
Pro

Interview practice question

Class impossible to unit test

Backend Engineering · OOP and Design Patterns · Beginner

A class creates its own database connection and HTTP client inside its methods, so you cannot unit test it without real systems. How do you fix it?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Hard-coded dependencies.
  • Inject via constructor.
  • Depend on interfaces.
  • Use fakes/mocks in tests.
  • Wire real implementations at startup.
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics