0
0
JUnittesting~5 mins

Fake objects in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a fake object in testing?
A fake object is a simple implementation of an interface or class used in tests to simulate real behavior with minimal logic. It helps isolate the code under test by replacing complex dependencies.
Click to reveal answer
intermediate
How does a fake object differ from a mock?
A fake object has working implementations but simplified, while a mock is used to verify interactions and expectations during tests.
Click to reveal answer
beginner
Why use fake objects in JUnit tests?
They speed up tests by avoiding slow or complex real components, and help test code in isolation without external dependencies.
Click to reveal answer
intermediate
Example of a fake object in JUnit for a payment service?
class FakePaymentService implements PaymentService { public boolean pay(double amount) { return true; } } This fake always returns success to test payment logic without real transactions.
Click to reveal answer
beginner
What is a key benefit of using fake objects over real implementations in tests?
They make tests faster, more reliable, and easier to write by removing dependencies on external systems or complex logic.
Click to reveal answer
What is the main purpose of a fake object in testing?
ATo replace the entire application
BTo simulate a real component with simple logic
CTo verify method calls and interactions
DTo slow down test execution
Which of the following is true about fake objects?
AThey are never used in JUnit tests
BThey are used to verify interactions only
CThey contain complex business logic
DThey provide simplified working implementations
In JUnit, why might you use a fake object instead of the real service?
ATo avoid external dependencies and speed up tests
BTo make tests slower
CTo increase test complexity
DTo test the real service behavior
Which is NOT a characteristic of a fake object?
ASimplified implementation
BUsed for isolation in tests
CVerifies method call counts
DReplaces complex dependencies
What would a fake payment service likely do in a test?
AAlways return success without real processing
BPerform real transactions
CAlways return failure
DThrow exceptions randomly
Explain what a fake object is and why it is useful in JUnit testing.
Think about replacing complex parts with simple versions in tests.
You got /4 concepts.
    Describe the difference between a fake object and a mock in software testing.
    One simulates behavior, the other checks calls.
    You got /4 concepts.