0
0
Swiftprogramming~5 mins

XCTest framework basics in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AXCTest
BTestCase
CXCTestCase
DTestSuite
What prefix must test method names start with in XCTest?
Atest
Bcheck
Cverify
Dassert
What does XCTAssertEqual(a, b) do in a test?
AChecks if a is equal to b
BChecks if a is less than b
CChecks if a is not equal to b
DChecks if a is greater than b
When is tearDown() called in the XCTest lifecycle?
ABefore all tests start
BAfter all tests finish
CBefore each test method
DAfter each test method
Which of these is NOT a valid XCTAssert function?
AXCTAssertTrue
BXCTAssertComplete
CXCTAssertFail
DXCTAssertNil
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.