Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

unit testing swift ui

//    Correct result, tests succeeds
    func testAdditionCorrectResult() {
      let firstNumber = 5
      let secNumber = 9
        
      let result = firstNumber + secNumber

      // Check if the result of the addition is the expected one
      XCTAssertEqual(result, 14, "Result of addition is wrong!")
    }
//    Wrong result, tests fails
    func testAdditionWrongResult() {
      let firstNumber = 5
      let secNumber = 9
        
      let result = firstNumber + secNumber

      // Check if the result of the addition is the expected one
      XCTAssertEqual(result, 15, "Result of addition is wrong!")
    }
Source by www.raywenderlich.com #
 
PREVIOUS NEXT
Tagged: #unit #testing #swift #ui
ADD COMMENT
Topic
Name
8+4 =