https://developer.apple.com/videos/play/wwdc2019/413/
XCTest를 활용해 유닛테스트 해보기 (꼭 보기)
https://developer.apple.com/documentation/xctest
UnitTest는 테스트코드 작성의 기반으로 주로 함수
를 테스트한다.
(소스코드) XCTest 클래스가 사용된다.
Integration Test는 클래스
의 묶음이 잘 작동하는지 테스트한다.
User interface(UI) Test는 사용자 입장에서 테스트해본다고 생각하면 된다. (end to end, 블랙박스)
유닛테스트와 UI테스트가 추가됨
import XCTest
@testable import my_swift_algorithm
class my_swift_algorithmTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
유닛테스트를 하려면
XCTest 클래스를 import하고 (import XCTese
)
SubClass인 XCTestCase를 상속받아서 사용한다. (class MyiOSAppTests: XCTestCase
)
그리고 Count 클래스를 MyiOSApp 폴더 안에 생성하였기 때문에 import 해줘야 합니다.(@testable import MyiOSApp
)
함수는 testIncrementCounter()
처럼 test로 시작해야한다.
setUpWithError()
와tearDownWithError()
를 포함하고 있으며 흐름은 아래와 같다.
setUp은 테스트 전 앱이 시작되었는지 보장하는 역할을 하고
tearDown은 테스트 후 테스트로 인한 변화를 없애 다른 테스트에 영향이 없도록 해준다.
그냥 일반적으로 앱 만드는 것과 똑같이 하고
유닛테스트 하는 파일에
test로 시작하는 함수를 적고
func test~~() { ... }
왼쪽 버튼을 누르게 되면 테스트코드가 실행된다
우와! 나도 테스트 코드 쓴다!
스택 코드
https://velog.io/@msi753/알고리즘과-데이터-구조-기초-스택
타겟이 breakpoint.app 이구먼?
https://stackoverflow.com/questions/13884456/xcode-unit-testing/31570612#31570612