Recall & Review
beginner
What is the purpose of XCTAssertEqual in Swift testing?
XCTAssertEqual checks if two values are equal. If they are not, the test fails. It helps verify that the code produces the expected result.
Click to reveal answer
beginner
How does XCTAssertTrue work in Swift tests?
XCTAssertTrue checks if a condition is true. If the condition is false, the test fails. It is used to confirm that a boolean expression is true.
Click to reveal answer
beginner
Example: What will XCTAssertEqual(3 + 2, 5) do in a test?
It will pass because 3 + 2 equals 5, so the two values are equal.
Click to reveal answer
beginner
Example: What happens if XCTAssertTrue(2 > 3) is used in a test?
The test will fail because 2 > 3 is false, but XCTAssertTrue expects a true condition.
Click to reveal answer
beginner
Why are assertions like XCTAssertEqual and XCTAssertTrue important in testing?
They help catch mistakes early by checking if the code behaves as expected. This makes the code more reliable and easier to fix if something goes wrong.
Click to reveal answer
What does XCTAssertEqual(a, b) check in a test?
✗ Incorrect
XCTAssertEqual checks if the two values a and b are equal.
What happens if XCTAssertTrue(condition) receives a false condition?
✗ Incorrect
XCTAssertTrue expects a true condition; if false, the test fails.
Which assertion would you use to check if two strings are the same?
✗ Incorrect
XCTAssertEqual is used to check if two values, including strings, are equal.
If you want to check that a boolean variable is true, which assertion is best?
✗ Incorrect
XCTAssertTrue directly checks if a boolean variable is true.
Why use assertions in unit tests?
✗ Incorrect
Assertions verify that code behaves correctly, helping catch errors early.
Explain how XCTAssertEqual and XCTAssertTrue help in testing Swift code.
Think about what each assertion checks and why failing tests are useful.
You got /4 concepts.
Describe a simple example where you would use XCTAssertTrue in a test.
Imagine checking if something is true in your app.
You got /4 concepts.