Recall & Review
beginner
What is the XCTest framework used for in iOS development?
XCTest is used to write and run tests that check if your iOS app works correctly. It helps find bugs early by testing code automatically.
Click to reveal answer
beginner
How do you define a test case class in XCTest?You create a class that inherits from XCTestCase. Inside, you write test methods that start with the word 'test'.Click to reveal answer
intermediate
What is the purpose of the setUp() and tearDown() methods in XCTest?
setUp() runs before each test to prepare the environment. tearDown() runs after each test to clean up. They help keep tests independent.
Click to reveal answer
beginner
How do you check if two values are equal in an XCTest test method?
Use XCTAssertEqual(value1, value2) to verify that both values are the same. If not, the test fails.
Click to reveal answer
beginner
What happens when an assertion like XCTAssertTrue fails during a test?
The test is marked as failed but continues running. This shows that the code did not behave as expected.
Click to reveal answer
Which class should your test classes inherit from when using XCTest?
✗ Incorrect
Test classes must inherit from XCTestCase to use XCTest features.
What prefix must test method names start with in XCTest?
✗ Incorrect
Test methods must start with 'test' so XCTest can find and run them.
What is the role of the tearDown() method in XCTest?
✗ Incorrect
tearDown() cleans up resources after each test to avoid side effects.
Which assertion checks if a condition is true in XCTest?
✗ Incorrect
XCTAssertTrue checks if a condition is true; if not, the test fails.
What happens if an assertion fails during a test?
✗ Incorrect
When an assertion fails, the test is marked as failed but continues running.
Explain how to create and run a simple test case using XCTest in Swift.
Think about the class, method names, and how you check results.
You got /4 concepts.
Describe the purpose of setUp() and tearDown() methods in XCTest and why they are important.
Consider how tests stay independent and clean.
You got /4 concepts.