Recall & Review
beginner
What is a stub object in software testing?
A stub object is a simple fake version of a real object used in tests. It provides fixed responses to calls, helping isolate the part of the code being tested.
Click to reveal answer
beginner
Why do we use stub objects in unit tests?
We use stubs to replace complex or slow parts of the system, like databases or web services, so tests run fast and focus only on the code under test.
Click to reveal answer
intermediate
How does a stub differ from a mock object?
A stub provides preset responses but does not check how it was used. A mock also verifies if certain methods were called, adding behavior verification.
Click to reveal answer
intermediate
Example of a simple stub method in JUnit?
In JUnit, a stub can be a class that implements an interface and returns fixed values. For example, a stub for a payment service might always return success.Click to reveal answer
beginner
What is a key benefit of using stub objects?
They help isolate the unit of code being tested by removing dependencies on external systems, making tests reliable and fast.
Click to reveal answer
What does a stub object typically do in a test?
✗ Incorrect
A stub returns fixed responses to simulate parts of the system during testing.
Which is NOT a reason to use stub objects?
✗ Incorrect
Verifying method call order is a job for mocks, not stubs.
In JUnit, a stub class usually:
✗ Incorrect
A stub class implements interfaces and returns fixed values to simulate behavior.
Which statement about stub objects is true?
✗ Incorrect
Stubs replace real objects with simple versions to isolate tests.
What is the main difference between a stub and a mock?
✗ Incorrect
Stubs return fixed data; mocks also check how they were used.
Explain what a stub object is and why it is useful in unit testing.
Think about replacing parts of the system that are slow or complex.
You got /4 concepts.
Describe the difference between a stub and a mock object.
One just gives answers, the other checks behavior.
You got /3 concepts.