๋ฐ์ํ
- ๋จ์ ํ ์คํธ๋ผ๊ณ ํ๋ฉฐ ํ๋ก๊ทธ๋จ์ ๊ธฐ๋ณธ ๋จ์์ธ ๋ชจ๋์ ํ ์คํธ ํจ
- ๋ชจ๋์ด ์ ํด์ง ๊ธฐ๋ฅ์ ์ํํ๋์ง ํ ์คํธ ํจ(๋ชจ๋ ๋จ์๋ก ์ฝ๋๊ฐ ์์ฑ๋์ด์ผ ํจ)
FIRST ๊ธฐ์ค
- Fast(๋น ๋ฆ)
- ํ ์คํธ๋ ๋น ๋ฅด๊ฒ ์คํ๋์ด์ผ ํจ
- Independent/Isolated(๊ณ ๋ฆฝ๋จ)
- ํ ์คํธ๋ ์๋ก ์ํ๋ฅผ ๊ณต์ ํด์๋ ์๋จ
- Repeatable(๋ฐ๋ณต์ )
- ํ ์คํธ๋ฅผ ์คํํ ๋๋ง๋ค ๋์ผํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ด์ผ ํจ.
- ์ธ๋ถ ๋ฐ์ดํฐ๋ฅผ ๊ณต๊ธ์(external data Provider ๋คํธ์ํฌ ์๋น์ค ๋ก์ง ๊ฐ์ ๊ฒ), ๋์์ฑ(concurrency) ๋ฌธ์ ๋ก ์ธํด ๊ฐํ์ ์ค๋ฅ ๋ฐ์ ํ ์ ์์
- Self-validating(์๊ฐ ๊ฒ์ฆ)
- ํ ์คํธ๋ ์์ ํ ์๋ํ๋์ด์ผ ํจ.
- ๋ก๊ทธํ์ผ๋ก ํ๋ก๊ทธ๋๋จธ๊ฐ ํด์ํ๋ ๊ฒ์ด ์๋ ํ ์คํธ ์ผ์ด์ค์ ๋ํด “ํต๊ณผ” ๋๋ “์คํจ”์ฌ์ผํจ
- Timely(์ ์)
- ํ ์คํธ ์ฃผ๋ ๊ฐ๋ฐ TDD
- ์ด์์ ์ผ๋ก๋ ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑํ๊ณ production ์ฝ๋๋ฅผ ์์ฑํ๋๋ก ํจ
์์ ์ฝ๋
class LoginTests: XCTestCase {
func testLoginButtonEnabledWithValidCredentials() {
// Given
let viewController = LoginViewController()
let usernameField = UITextField()
let passwordField = UITextField()
let loginButton = UIButton()
viewController.usernameField = usernameField
viewController.passwordField = passwordField
viewController.loginButton = loginButton
// When
usernameField.text = "john.doe@example.com"
passwordField.text = "password123"
// Then
XCTAssertTrue(loginButton.isEnabled)
}
func testLoginButtonDisabledWithInvalidCredentials() {
// Given
let viewController = LoginViewController()
let usernameField = UITextField()
let passwordField = UITextField()
let loginButton = UIButton()
viewController.usernameField = usernameField
viewController.passwordField = passwordField
viewController.loginButton = loginButton
// When
usernameField.text = "invalid-username"
passwordField.text = "invalid-password"
// Then
XCTAssertFalse(loginButton.isEnabled)
}
}
๋ฉ์๋ ๊ท์น
- ๋ฉ์๋์ ์ด๋ฆ์ test๋ก ์์ํด์ผ ํจ(๊ทธ๋์ผ ๋ค์ด์๋ชฌ๋ ๋ฒํผ์ ๋๋ฌ ํ ์คํธ๋ฅผ ์คํํ ์ ์์)
- test ํ๋ฆฌํฝ์ค ๋ค์ ํ ์คํธ ๋์์ ๋ํ ์ค๋ช ์ ์ ์
๋ฉ์๋ ๋ด๋ถ ์น์
- Given
- ํ์ํ ๊ฐ์ ์ค์
- When
- ํ ์คํธ ์ค์ธ ์ฝ๋๋ฅผ ์คํ
- Then
- ์์ํ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ์ ํ๋ ์น์
- XCTestAssertions๋ฅผ ์ฌ์ฉํจ
์ฅ์
- ์ฝ๋์ ๋ชจ๋ํ
- ์ฝ๋๋ฅผ ๋ ๋ฆฝ์ ์ด๊ฒ ๋ง๋ค ์ ์์
- ๋ฆฌํฉํ ๋ง ๊ฐ๋ฅ
- ๊ฐ๋ฐ -> ํ ์คํธ -> ๋ฐฐํฌ ์๋ํ ํ์ดํ๋ผ์ธ ๊ตฌ์ถ๊ฐ๋ฅ
- ๋ชจ๋ ๋จ์์ ํ ์คํธ => ์ฑ ์ ์ฒด ๋น๋ x, ๋ชจ๋ ๋ณ๋ก ํ ์คํธ ๊ฐ๋ฅ
๋จ์
- ํ ์คํธ ์ผ์ด์ค ์์ฑ ๋๋ฌธ์ ๊ด๋ จ ์ฝ๋ ์ถ๊ฐ ๋์ด์ผ ํจ
- ๊ฐ๋ฐ ์๊ฐ ์ฆ๊ฐ
- ํฐ ์๋น์ค์ ๊ฒฝ์ฐ ๊ธฐํ์ ๋ณ๊ฒฝ์ด ์ฆ์ ์ ์๊ณ ๊ธฐ๋ฅ์ด ์ถ๊ฐ ๋๋ฉฐ ๊ธฐ์กด์ ์๋ ํ ์คํธ ์ผ์ด์ค๋ฅผ ๋ค์ ์์ฑํด์ผ ํ๋ ๊ฒฝ์ฐ ์๊น
์ฐธ๊ณ ์ฌ์ดํธ ๋ฐ ์ถ์ฒ
UnitTest: https://ios-development.tistory.com/334
UITest : http://yoonbumtae.com/?p=4020
728x90
๋ฐ์ํ
'๐ iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS/Swift] ๋๊ธฐ(sync) ํ ์คํธ (0) | 2023.04.13 |
---|---|
[iOS/Swift] XCTestCase ์์ฑํ๊ธฐ (0) | 2023.04.13 |
[RxSwift] passing viewmodel data to viewController (0) | 2023.03.25 |
[iOS/Swift] UICollectionView Dynamic Height with AutoConstraint (0) | 2023.03.25 |
[iOS/Xcode] Pod file not found ์ด์ (0) | 2023.03.23 |
๋๊ธ