Recall & Review
beginner
What is the main challenge when testing async code?
The main challenge is that async code runs in the background, so tests must wait for the async tasks to complete before checking results.
Click to reveal answer
beginner
What Swift feature helps to write tests for async functions?
Swift uses the
async keyword in test functions and await to wait for async calls to finish.Click to reveal answer
intermediate
How do you tell XCTest to wait for an async operation to finish?
You mark the test method with
async and use await inside it to pause until the async operation completes.Click to reveal answer
intermediate
What is an XCTestExpectation and when is it used?
An
XCTestExpectation is used to tell the test to wait for an async event to happen, especially when not using async/await syntax.Click to reveal answer
advanced
Why is it important to avoid blocking the main thread in async tests?
Blocking the main thread can cause deadlocks or freeze the test runner, so async tests should use proper async patterns to stay responsive.
Click to reveal answer
Which keyword do you use in Swift to wait for an async function to complete in a test?
✗ Incorrect
The
await keyword pauses the test until the async function finishes.How do you mark a test function in Swift that tests async code?
✗ Incorrect
You add
async to the test function so it can use await inside.What does
XCTestExpectation help with?✗ Incorrect
XCTestExpectation lets tests wait for async events to complete.What happens if you block the main thread in async tests?
✗ Incorrect
Blocking the main thread can cause the test to freeze or deadlock.
Which is the best way to test async code in Swift?
✗ Incorrect
Using async test functions with await is the cleanest and safest way.
Explain how to write a simple async test function in Swift using XCTest.
Think about marking the test function and how to pause for async calls.
You got /4 concepts.
Describe the role of XCTestExpectation in testing asynchronous code.
Consider how tests wait for background tasks before async/await was common.
You got /4 concepts.