0
0
Swiftprogramming~10 mins

XCTest framework basics in 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 import the XCTest framework.

Swift
import [1]
Drag options to blanks, or click blank then click option'
AXCTest
BFoundation
CUIKit
DSwiftUI
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Foundation instead of XCTest.
Forgetting to import any framework.
2fill in blank
medium

Complete the code to define a test case class named MyTests.

Swift
class MyTests: [1] { }
Drag options to blanks, or click blank then click option'
AXCTestCase
BNSObject
CUIViewController
DTestSuite
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from NSObject or UIViewController instead of XCTestCase.
Not inheriting from any class.
3fill in blank
hard

Fix the error in the test method declaration to make it a valid XCTest test method.

Swift
func [1]() { XCTAssertTrue(true) }
Drag options to blanks, or click blank then click option'
AexampleTest
BtestExample
CTestExample
Dexample
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not start with 'test'.
Capitalizing the first letter of the method name.
4fill in blank
hard

Fill both blanks to create a test method that checks if 2 + 2 equals 4.

Swift
func [1]() {
    XCTAssertEqual([2], 4)
}
Drag options to blanks, or click blank then click option'
AtestAddition
B2 + 2
C3 + 1
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not start with 'test'.
Using incorrect expressions inside XCTAssertEqual.
5fill in blank
hard

Fill all three blanks to write a test method that fails if a string is empty.

Swift
func [1]() {
    let text = "Hello"
    XCTAssertFalse([2].[3])
}
Drag options to blanks, or click blank then click option'
AtestStringIsNotEmpty
Btext
CisEmpty
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not start with 'test'.
Using wrong variable names or properties.