← Quiz: SOLID in Java: all 10 questions
Quiz: SOLID in Java · Question 5 of 10
Why is ResultService(ResultStore store, Notifier notifier) easier to test than a class that does new MySqlStore() insid…
Why is ResultService(ResultStore store, Notifier notifier) easier to test than a class that does new MySqlStore() inside?
- A.Constructors run faster than
new - B.Interfaces use less memory
- C.A test can pass an in-memory store and a fake notifier, so no real database or SMS gateway is needed
- D.MySQL cannot be used from Java tests
Answer & explanation
Correct answer: A test can pass an in-memory store and a fake notifier, so no real database or SMS gateway is needed
Injecting dependencies through the constructor lets tests choose lightweight replacements.
Can you get the rest right without peeking?
Take the timed Quiz: SOLID in Java quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →