0
0
JUnittesting~5 mins

Stub objects in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AReturns fixed responses to method calls
BVerifies if methods were called correctly
CRuns the full real implementation
DGenerates random data for testing
Which is NOT a reason to use stub objects?
AVerify the order of method calls
BIsolate the code under test
CAvoid using real external systems
DSpeed up tests by avoiding slow dependencies
In JUnit, a stub class usually:
AGenerates test reports
BExtends the test class
CRuns the real database queries
DImplements an interface with fixed return values
Which statement about stub objects is true?
AThey check if methods were called correctly
BThey replace real objects with simple versions
CThey are used to test UI components
DThey slow down test execution
What is the main difference between a stub and a mock?
AStubs are used only in integration tests
BMocks provide fixed responses; stubs verify interactions
CStubs provide fixed responses; mocks verify interactions
DMocks are slower than stubs
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.