Recall & Review
beginner
What is a test double in software testing?
A test double is a simple object that stands in for a real object during testing. It helps isolate the part of the code being tested by mimicking the behavior of real components.
Click to reveal answer
intermediate
What is the difference between a mock and a stub?
A stub provides predefined responses to calls made during the test, while a mock also records how it was used, allowing verification of interactions.
Click to reveal answer
beginner
Why use mocks in Swift unit tests?
Mocks help check if certain methods were called and with what data, making sure the tested code interacts correctly with other parts.
Click to reveal answer
intermediate
How does a stub help in testing asynchronous code?
A stub can return fixed data immediately or after a delay, simulating asynchronous responses without real network calls.
Click to reveal answer
beginner
Give an example of when to use a stub instead of a mock.
Use a stub when you only need to provide fixed data for a test, like returning a canned response from a database, without checking how it was called.
Click to reveal answer
Which test double records how it was used during a test?
✗ Incorrect
Mocks record interactions so you can verify if methods were called as expected.
What is the main purpose of a stub in testing?
✗ Incorrect
Stubs provide fixed responses to help tests run without real dependencies.
In Swift, which test double would you use to check if a function was called with specific arguments?
✗ Incorrect
Mocks allow verification of method calls and arguments.
Which of these is NOT a typical use of test doubles?
✗ Incorrect
Test doubles replace code dependencies, not UI elements.
What is a key benefit of using test doubles in unit testing?
✗ Incorrect
Test doubles isolate the code under test by replacing dependencies.
Explain the roles of mocks and stubs in unit testing and when to use each.
Think about whether you need to verify interactions or just provide data.
You got /4 concepts.
Describe how test doubles help improve the quality and speed of Swift unit tests.
Consider what happens if you test with real network or database calls.
You got /4 concepts.