์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- RxSwift
- DynamicIsland
- 3์ฃผ์ฐจ
- letswift
- test
- KoreaMango
- wwdc2023
- 2023
- xcode15
- WWDC
- Unit
- watchapp
- Swift
- ActivityKit
- 2์ฃผ์ฐจ
- tutorial
- ํ๋ก๊ทธ๋๋จธ์ค
- ๋ํ์ํ
- ๊ฐ๋ฐ์
- ์ฝฉ์ธ์ํ๋ก์ ํธ
- fruta
- 1์ฃผ์ฐจ
- ios
- swiftUI
- SwiftData
- unittest
- watchkit
- @Model
- tutorials
- ํ๊ณ
- Today
- Total
KoreaMango ๋๋ฌด
[iOS] Unit Test - ๋จ์ ํ ์คํธ ์ด๋ป๊ฒ ํ๋๊ฑด๋ฐ.. (2) ๋ณธ๋ฌธ
[iOS] Unit Test - ๋จ์ ํ ์คํธ ์ด๋ป๊ฒ ํ๋๊ฑด๋ฐ.. (2)
KoreaMango 2022. 7. 8. 00:49๐์๋ก
์ด๋ฒ ๊ธ์ ์ผ๊ณฐ ์์นด๋ฐ๋ฏธ์ ํ ๊ฐ์๋ฅผ ๊ฑฐ์ ๋ฐ๋ผ์ผ๋ค์ํผ.. ๋ค.. ๊ทธ๋ ์ต๋๋ค..
์ดํดํ๋ฉด์ ์ฐ๊ณ ์์ด์ ใ ใ ,,
์ด ํํธ๋ Test file์ ๋ณด๋ฉฐ ๋ง๋ฌด๋ฆฌ ์ง์ต๋๋ค.
XCTest
XCTest๋ ์ ๋ ํ ์คํธ, ํผํฌ๋จผ์ค ํ ์คํธ, UI ํ ์คํธ๋ฅผ ๋ง๋ค๊ณ ์คํํ๋ ํ๋ ์ ์ํฌ์ด๋ค.
XCTestCase
ํ ์คํธ ํด๋์ค๊ฐ ์์ํ๊ณ ์๋ XCTestCase๋ ๋ฌด์์ผ๊น?
XCTestCase ๋ ์ถ์ ํด๋์ค์ธ XCTest์ ํ์ ํด๋์ค๋ก, ํ ์คํธ๋ฅผ ์์ฑํ๊ธฐ ์ํด ์์กํด์ผ ํ๋ ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํด๋์ค์ด๋ค.
XCTest๋ ํ ์คํธ๋ฅผ ์ํ ํ๋ ์ ์ํฌ์ ์ด๋ฆ์ด๊ธฐ๋ ํ๊ณ , ํ ์คํธ์์ ๊ฐ์ฅ ๊ธฐ๋ณธ์ด ๋๋ ์ถ์ ํด๋์ค์ ์ด๋ฆ์ด๊ธฐ๋ ํ๋ค.
XCTestCase๋ฅผ ์์๋ฐ์ ํด๋์ค์์๋ test์์ ์ฌ์ฉ๋๋ ๋ค์ํ ํ๋กํผํฐ์ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
setUpWithError()
setUpWithError()๋ ๊ฐ๊ฐ์ test case ๊ฐ ์คํ๋๊ธฐ ์ ๋ง๋ค ํธ์ถ๋์ด ๊ฐ ํ ์คํธ๊ฐ ๋ชจ๋๊ฐ์ ์ํ์ ์กฐ๊ฑด์์ ์คํ๋ ์ ์๋๋ก ๋ง๋ค์ด ์ค ์ ์๋ ๋ฉ์๋์ด๋ค.
tearDownWithError()
tearDownWithError()๋ ๊ฐ๊ฐ์ test ์คํ์ด ๋๋ ํ ๋ง๋ค ํธ์ถ๋๋ ๋ฉ์๋์ด๋ค. ๋ณดํต setUpWithError()์์ ์ค์ ํ ๊ฐ๋ค์ ํด์ ํ ๋ ์ฌ์ฉ๋๋ค.
ํธ์ถ ์์
setUpWithError()
TestCase 1
tearDownWithError()
setUpWithError()
TestCase 2
tearDownWithError()
setUpWithError()
TestCase 3
...
setUp() ๊ณผ tearDown() ๋ฉ์๋ ์ฐจ์ด
setUp() ๊ณผ tearDown() ๋ฉ์๋์ setUpWithError(), tearDownWithError()์ ์ฐจ์ด๋ ์๋ฌ๋ฅผ throw ํ ์ ์๋๋์ ๋ํ ์ฐจ์ด์ด๋ค. ํ ์คํธ ๋ฉ์๋๋ฅผ throw ๋ฉ์๋๋ก ๋ง๋ค์ด์ฃผ๋ฉด, ๋ด๋ถ์์ ๋ฐ๋ก ์๋ฌ ํธ๋ค๋ง์ ํด์ฃผ๋ ์์ ์์ด ํ ์คํธ๋ฅผ ์์ฑํ ์ ์๋ค๋ ์ด์ ์ด ์๋ค. ์๋๋ setUp()๊ณผ tearDown() ๋ฉ์๋๊ฐ ๊ธฐ๋ณธ ๋ฉ์๋๋ก ์ ๊ณต์ด ๋์๋๋ฐ xcode 11.4 ๋ฒ์ ์ดํ๋ก ๊ธฐ๋ณธ์ผ๋ก setUpWithError(), tearDownWithError()๋ฅผ ์ ๊ณตํ๊ณ ์์ด์.
์์ธํ ๋ด์ฉ์
testExample()
test๋ก ์์ํ๋ ๋ฉ์๋๋ ์ฐ๋ฆฌ๊ฐ ์์ฑํด์ผํ test case ๊ฐ ๋๋ ๋ฉ์๋์ ๋๋ค. ์ฐ๋ฆฌ๊ฐ ํ ์คํธํ ๋ด์ฉ์ ๋ฉ์๋๋ก ์์ฑํด๋ณผ ์ ์์ต๋๋ค. ๋ฉ์๋ ๋ค์ด๋ฐ์ ์์์ ๋ฌด์กฐ๊ฑด test๋ก ์์๋์ด์ผ ํ๋ค.
๐๐ป Ref