D. Missing return statement; add return "Fixed data"
Solution
Step 1: Identify the method signature and body
The method declares it returns a String but only calls print without returning anything.
Step 2: Fix the missing return
Replace print("Fixed data") with return "Fixed data" to satisfy the return type.
Final Answer:
Missing return statement; add return "Fixed data" -> Option D
Quick Check:
Stub must return value, not print [OK]
Hint: Return values, don't print in stubs [OK]
Common Mistakes:
Confusing print with return
Changing method name unnecessarily
Changing return type incorrectly
5. You want to test a Swift class Downloader that calls a network service. To avoid real network calls, you create a mock service that records if download() was called and a stub that returns fixed data. Which approach correctly combines mocks and stubs for this test?
hard
A. Use only a mock that returns fixed data without recording calls
B. Use only a stub that records calls and returns data
C. Use a mock to record download() calls and a stub to return fixed data when fetchData() is called
D. Use real network service to ensure accurate testing
Solution
Step 1: Understand roles of mocks and stubs
Mocks record interactions like method calls; stubs provide fixed return data.
Step 2: Apply correct combination
Use a mock to check if download() was called, and a stub to supply fixed data for fetchData() to avoid real network calls.
Final Answer:
Use a mock to record download() calls and a stub to return fixed data when fetchData() is called -> Option C
Quick Check:
Mock records calls + Stub returns data [OK]
Hint: Mocks track calls; stubs provide data [OK]
Common Mistakes:
Using only one test double type
Relying on real network in tests
Confusing mock and stub roles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.