0
0
iOS Swiftmobile~10 mins

XCTest framework in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a test case class in XCTest.

iOS Swift
import XCTest

class MyTests: [1] {
}
Drag options to blanks, or click blank then click option'
AXCTestCase
BUIViewController
CNSObject
DAppDelegate
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIViewController instead of XCTestCase.
Forgetting to inherit from any class.
2fill in blank
medium

Complete the code to define a test method that XCTest will run.

iOS Swift
func [1]() {
    XCTAssertEqual(2 + 2, 4)
}
Drag options to blanks, or click blank then click option'
AadditionTest
BtestAddition
CcheckAddition
DverifyAddition
Attempts:
3 left
💡 Hint
Common Mistakes
Naming test methods without the 'test' prefix.
Using spaces or special characters in method names.
3fill in blank
hard

Fix the error in the assertion to check if a value is true.

iOS Swift
XCTAssert[1](isReady)
Drag options to blanks, or click blank then click option'
ANil
BEqual
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using XCTAssertFalse when expecting true.
Using XCTAssertEqual for boolean checks.
4fill in blank
hard

Fill both blanks to set up and tear down test resources.

iOS Swift
override func [1]() {
    super.[1]()
    // setup code here
}

override func [2]() {
    super.[2]()
    // teardown code here
}
Drag options to blanks, or click blank then click option'
AsetUp
BtearDown
CviewDidLoad
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using viewDidLoad instead of setUp or tearDown.
Not calling super in overridden methods.
5fill in blank
hard

Fill all three blanks to write a test that expects an error to be thrown.

iOS Swift
func testError() [3] {
    XCTAssertThrows[1](try someFunctionThat[2](), "Expected error")
    // Additional checks can be done here
}
Drag options to blanks, or click blank then click option'
AError
BThrows
Cthrows
DThrow
Attempts:
3 left
💡 Hint
Common Mistakes
Using XCTAssertThrow instead of XCTAssertThrowsError.
Omitting 'try' before the function call.
Not marking the test method with 'throws'.