Recall & Review
beginner
What is a protocol in Swift?
A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. Classes, structs, or enums can adopt protocols to provide actual implementations.
Click to reveal answer
beginner
Why do we use mock objects in iOS testing?
Mock objects simulate real objects in tests. They help isolate the code being tested by replacing dependencies with controllable and predictable versions, making tests faster and more reliable.
Click to reveal answer
intermediate
How do protocols help with creating mock objects?
Protocols allow you to define interfaces that real objects and mock objects both conform to. This lets you swap the real implementation with a mock one easily during testing without changing the code that uses them.
Click to reveal answer
intermediate
What is a key benefit of using protocols for dependency injection?
Protocols enable dependency injection by allowing you to pass any object that conforms to the protocol. This makes your code more flexible and testable because you can inject mock objects during tests.
Click to reveal answer
beginner
In Swift, how do you declare that a class conforms to a protocol?You add the protocol name after the class name, separated by a colon. For example: class MyClass: MyProtocol { }Click to reveal answer
What is the main purpose of a mock object in testing?
✗ Incorrect
Mock objects replace real objects during testing to control behavior and isolate the code under test.
Which Swift feature allows you to define a set of methods that a class must implement?
✗ Incorrect
Protocols define a blueprint of methods and properties that conforming types must implement.
How do mock objects improve test reliability?
✗ Incorrect
Mock objects isolate dependencies and provide predictable behavior, making tests more reliable.
What keyword do you use in Swift to declare a protocol?
✗ Incorrect
The keyword protocol is used to declare a protocol in Swift.
Which of these is a benefit of using protocols for dependency injection?
✗ Incorrect
Protocols allow easy swapping of implementations, which improves testability and flexibility.
Explain how protocols and mock objects work together to improve testing in Swift.
Think about how you can replace a real part of your app with a fake one during tests.
You got /4 concepts.
Describe the steps to create a mock object for a protocol in Swift.
Start with the protocol, then build a fake version that follows its rules.
You got /4 concepts.