🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Unit Testing and TDD: all 10 questions

Quiz: Unit Testing and TDD · Question 5 of 10

What is the difference between a stub and a mock?

What is the difference between a stub and a mock?

  1. A.There is no difference
  2. B.A stub is used only in Java
  3. C.A mock returns fixed values; a stub records calls
  4. D.A stub returns fixed answers; a mock also records how it was called so the test can check it
Answer & explanation

Correct answer: A stub returns fixed answers; a mock also records how it was called so the test can check it

Mocks let you verify interactions, such as "send was called once".

Can you get the rest right without peeking?

Take the timed Quiz: Unit Testing and TDD quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →