728x90
๋ฐ์ํ
์ฐธ๊ณ ์ฌ์ดํธ ๋ฐ ์ถ์ฒ
์๋ฌธ Kodeco์ iOS Unit Testing and UI Testing Tutorial์ ๋ฒ์ญํ yoonbumatae์ ๊ธ์ ์ ๋ฆฌํ ํฌ์คํ ์ ๋๋ค. ๋ ์์ธํ ๋ด์ฉ์ ์ฐธ๊ณ ํ์๋ ค๋ฉด ์๋ ๋ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ์ธ์!
https://www.kodeco.com/21020457-ios-unit-testing-and-ui-testing-tutorial
Unit Test & Class ์์ฑ
- navigator์์ ๋ค์ด์๋ชฌ๋ ๋ชจ์์ ๋ฒํผ์ ๋๋ฅด๋ฉด ํ๋จ์ + ๋ชจ์์ ๋๋ฌ ์๋ก์ด Unit Test์ Unit Test์ ํ์ํ Class๋ฅผ ์์ฑํ ์ ์์
- Target์ ์ด๋ฆ์ ์ค์ ํ๊ณ finish๋ฅผ ๋๋ฅด๋ฉด TestNavigator์ ์๋ก์ด Target์ด ์์ฑ๋ ๊ฒ์ ํ์ธํ ์ ์์
XCTestCase
func setUpWithError() throws
- ํ ์คํธ ์ผ์ด์ค๊ฐ ์์ ๋๊ธฐ ์ ์ ๋น๋๊ธฐ ์ํ๋ฅผ ์ค๋นํ๊ธฐ ์ํ XCTest๋ setUp(completion:)์ ํธ์ถํจ ์ด ๋ฉ์๋๊ฐ ํธ์ถ๋๊ณ ๋๋ฉด setUpWithError ๋ฉ์๋๋ฅผ ํธ์ถํ๊ณ ๊ทธ ๋ค setUP()์ ํธ์ถ
- state preparation์ด ์๋ฌ๋ฅผ ๋์ง ์๋ ์๋๋ฐ ๊ทธ ๋ ํด๋น ๋ฉ์๋๋ฅผ ์ ์ ํ ์ ์๊ณ XCTest๋ ์๋ฌ๊ฐ ๋ฐ์์ ํ ์คํธ๋ฅผ ์คํจํ ๊ฒ์ผ๋ก ๊ฐ์ฃผํจ
- ๋ง์ฝ ์คํจ๊ฐ ์๋ ๊ฑด๋ ๋ฐ๊ณ ์ถ์ ๊ฒฝ์ฐ (๋คํธ์ํฌ๊ฐ ๋ถ๊ฐ๋ฅํ ์ํ์์ ํ ์คํธ ์ผ์ด์ค๋ฅผ ์คํํ๋ ๊ฒ์ด ๋ง์ง ์์ ๋ ๋ฑ) XCTSkip์ ์ฌ์ฉํจ
- ํ ์คํธ ์ผ์ด์ค๋ฅผ ์คํํ๊ธฐ ์ํด ํ์ํ ์ค์ ์ฝ๋๋ฅผ ์ฌ๊ธฐ์ ์ ๋ ฅํ๊ณ ๊ฐ ํ ์คํธ ๋ฉ์๋๋ฅผ ํธ์ถํ๊ธฐ ์ ์ ํด๋น ๋ฉ์๋๊ฐ ํธ์ถ๋จ
func tearDownWithError() throws
- ๊ฐ ํ ์คํธ๊ฐ ์๋ฃ๋๋ฉด XCTest๋ tearDown()์ ํธ์ถํ๊ณ ๊ทธ ๋ค tearDownWithError()๋ฅผ ํธ์ถํจ. ๊ทธ ํ TearDown(completion:) ์ด ํธ์ถ ๋จ
- ์ํ ๊ฐ์ ์ง์ฐ๋ ๊ณผ์ ์์ ์๋ฌ๊ฐ ๋ฐ์๋ ๊ฒฝ์ฐ tearDown(completion:) ๋ฉ์๋๋ฅผ ์ฌ์ ์ ํ์ฌ ์ฌ์ฉํจ
- XCTest๋ ์ค๋ฅ ๋ฐ์ํ๋ฉด ํ ์คํธ๋ฅผ ์คํจํ ๊ฒ์ผ๋ก ํ์ํ๋ค. ๋ง์ฝ ์คํจ๊ฐ ์๋ ๊ฑด๋๋ฐ๊ณ ์ถ์ ๊ฒฝ์ฐ XCTSkip์ ๋ฐ์์ํด
- tearDown ์ฝ๋๋ฅผ ์์ฑ. ๊ฐ ํ ์คํธ ํจ์๊ฐ ํธ์ถ๋ ์ดํ์ ํด๋น ํจ์๊ฐ ํธ์ถ ๋จ
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.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
- ํ ์คํธ ํจ์๋ test~ ๋ก ์์ํ๋๋ก ์์ฑํจ
- ํด๋น ํจ์ ์์ ๋ค์ด์๋ชฌ๋ ๋ฒํผ์ ๋๋ฅด๋ฉด ํด๋น ํ ์คํธ ์ผ์ด์ค๊ฐ ์คํ๋จ
func testPerformanceExample() throws {
// This is an example of a performance test case.
measure(metrics: [
XCTClockMetric(), // ๊ฒฝ๊ณผ ์๊ฐ ์ธก์
XCTCPUMetric(), // cpu ์๊ฐ, ์ฃผ๊ธฐ ๋ฐ ๋ช
๋ น์ด ์๋ฅผ ํฌํจํ cpuํ๋ ์ถ์
XCTStorageMetric(), // ํ
์คํธ๋ ์ฝ๋๊ฐ ์คํ ๋ฆฌ์ง์ ์ฐ๋ ๋ฐ์ดํฐ ์
XCTMemoryMetric() // ์ฌ์ฉ๋ ์ค์ ๋ฉ๋ชจ๋ฆฌ์ ์
]) {
sut.check(guess: 100)
}
}
- ์ฑ๋ฅ ์ฝ๋๋ฅผ ์์ฑ. ์ฝ๋ ๋ธ๋ก์ ์ฑ๋ฅ์ ์ธก์ ํจ
- measure ์ ๋ํ ๋ถ๋ถ์ https://developer.apple.com/documentation/xctest/xctestcase/1496290-measure#parameters ๋ฅผ ์ฐธ๊ณ
728x90
๋ฐ์ํ
'๐ iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS/Swift] ๋น๋๊ธฐ(async) ํ ์คํธ (0) | 2023.04.14 |
---|---|
[iOS/Swift] ๋๊ธฐ(sync) ํ ์คํธ (0) | 2023.04.13 |
[iOS/Swift] Unit Test ๋? (0) | 2023.04.10 |
[RxSwift] passing viewmodel data to viewController (0) | 2023.03.25 |
[iOS/Swift] UICollectionView Dynamic Height with AutoConstraint (0) | 2023.03.25 |
๋๊ธ