https://velog.io/@minni/TDD%EC%99%80-Swift-XCTest-%ED%99%9C%EC%9A%A9%ED%95%98%EA%B8%B0
https://www.raywenderlich.com/21020457-ios-unit-testing-and-ui-testing-tutorial
프로젝트명 + Tests
이름의 클래스가 XCTest
를 import 하고, XCTestCase
를 상속받은 채로 생성됨setUpWithError()
, tearDownWithError()
라는 오버라이딩 메서드 자동 생성testExample()
, testPerformanceExample()
자동 생성import XCTest
@testable import PokerGameApp // 기능을 테스트할 모델 가져오기 - 모델의 내부 타입과 메서드에 접근 가능하게 함
class PokerGameAppTests: XCTestCase {
var systemUnderTest: PokerGame! // System Under Test
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
try super.setUpWithError()
systemUnderTest = PokerGame(playerNames: ["A", "B"]) // 테스트할 객체 생성
// SUT는 setUpWithError()에서 만들고, tearDownWithError()에서 해제하는 것이 좋다.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
systemUnderTest = nil // 테스트한 객체 릴리즈
try super.tearDownWithError()
}
}
import XCTest
아래에 기능을 테스트할 모델을 가져온다. @testable import 모델명
PokerGameAppTests의 프로퍼티로 var systemUnderTest: 테스트할 객체
를 선언한다.
SUT는 setUpWithError()에서 만들고, tearDownWithError()에서 해제하는 것이 좋다.
setUpWithError()
에 아래 코드를 추가한다.
try super.setUpWithError()
systemUnderTest = PokerGame()
테스트할 객체를 클래스 수준에서 생성해, 테스트 클래스의 모든 테스트가 SUT 객체의 프로퍼티와 메서드에 접근할 수 있도록 한다.
set up = 설립하다
tearDownWithError()
에 아래 코드를 추가한다.
systemUnderTest = nil
try super.tearDownWithError()
SUT 객체를 릴리즈하는 작업이다.
tear down = 해체하다
XCTAssert...
메서드를 활용한다.