0
0
JUnittesting~5 mins

Choosing the right test double in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a test double in software testing?
A test double is a simplified object that stands in for a real object during testing to isolate the code being tested.
Click to reveal answer
beginner
Name the four common types of test doubles.
The four common types are: Dummy, Stub, Mock, and Spy.
Click to reveal answer
beginner
When should you use a Dummy test double?
Use a Dummy when you need to pass an object but it is not used by the test, just to satisfy method parameters.
Click to reveal answer
intermediate
What is the main purpose of a Stub?
A Stub provides predefined responses to calls made during the test, controlling indirect inputs to the system under test.
Click to reveal answer
intermediate
How does a Mock differ from a Stub?
A Mock not only provides predefined responses but also verifies that certain interactions happened, like method calls with specific arguments.
Click to reveal answer
Which test double is used only to fill parameter lists but is never actually used in the test?
ADummy
BStub
CMock
DSpy
Which test double helps control indirect inputs by returning fixed data during tests?
AMock
BStub
CDummy
DSpy
Which test double verifies that specific methods were called with expected arguments?
ADummy
BStub
CMock
DSpy
If you want to record how a real object was used during a test, which test double would you use?
ADummy
BStub
CMock
DSpy
Which test double should you choose if you only want to isolate the tested code without verifying interactions?
AStub
BDummy
CSpy
DMock
Explain the differences between Dummy, Stub, Mock, and Spy test doubles and when to use each.
Think about their roles in controlling inputs and verifying behavior.
You got /4 concepts.
    Describe a real-life example where choosing the right test double improves test reliability.
    Consider how test doubles help avoid dependencies and make tests faster.
    You got /3 concepts.