Recall & Review
beginner
What is XCTest in Swift?
XCTest is a framework provided by Apple to write and run tests for Swift code. It helps check if your code works as expected by running test cases automatically.
Click to reveal answer
beginner
What is a test case in XCTest?
A test case is a class that inherits from XCTestCase. It contains one or more test methods that check specific parts of your code to make sure they behave correctly.Click to reveal answer
beginner
How do you write a test method in XCTest?
A test method is a function inside a test case class. It must start with the word 'test' and contain assertions to verify code behavior. For example:
func testAddition() { XCTAssertEqual(2 + 2, 4) }Click to reveal answer
beginner
What is the purpose of XCTAssert functions?
XCTAssert functions check if a condition is true during a test. If the condition fails, the test fails. Examples include XCTAssertEqual, XCTAssertTrue, XCTAssertNil, etc.
Click to reveal answer
intermediate
What are setUp() and tearDown() methods used for in XCTest?
setUp() runs before each test method to prepare the environment. tearDown() runs after each test method to clean up. They help keep tests independent and organized.
Click to reveal answer
Which class should your test case inherit from in XCTest?
✗ Incorrect
In XCTest, all test cases must inherit from XCTestCase to gain testing capabilities.
What prefix must test method names start with in XCTest?
✗ Incorrect
Test methods must start with 'test' so XCTest can recognize and run them automatically.
What does XCTAssertEqual(a, b) do in a test?
✗ Incorrect
XCTAssertEqual checks if two values are equal. If not, the test fails.
When is tearDown() called in the XCTest lifecycle?
✗ Incorrect
tearDown() runs after each test method to clean up resources.
Which of these is NOT a valid XCTAssert function?
✗ Incorrect
XCTAssertComplete does not exist in XCTest. The others are valid assertion functions.
Explain how to create a basic test case using XCTest and what components it should include.
Think about the class, methods, and assertions needed.
You got /4 concepts.
Describe the role of setUp() and tearDown() in managing test environment in XCTest.
Consider when these methods run and why they help tests.
You got /4 concepts.