Add the test subject

ในการเขียน Automated test จะต้องมีเป้าหมายของการทดสอบเสมอ สำหรับ unit test เป้าหมายของเราก็คือ class นั่นเอง

  1. สร้างไฟล์ใหม่ คลิกขวาที่ xctest_example > New File...

  2. เลือก Swift File

  3. ตั้งชื่อว่า Adder.swift แล้วกด Create

  4. จะมีไฟล์ใหม่เกิดขึ้น และ เปิด Editor ให้อัตโนมัติ

  5. เพิ่ม Code นี้เข้าไปใน Adder.swift

    public class Adder {
    
     public init() { }
    
     public func add(first: Int, second: Int) -> Int {
         return first + second
     }
    }
    

results matching ""

    No results matching ""