๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŽ iOS

[iOS/Swift] ๋™๊ธฐ(sync) ํ…Œ์ŠคํŠธ

by ํ‹ด๋”” 2023. 4. 13.
728x90
๋ฐ˜์‘ํ˜•

์ฐธ๊ณ  ์‚ฌ์ดํŠธ ๋ฐ ์ถœ์ฒ˜

์›๋ฌธ Kodeco์˜ iOS Unit Testing and UI Testing Tutorial์„ ๋ฒˆ์—ญํ•œ yoonbumatae์˜ ๊ธ€์„ ์ •๋ฆฌํ•œ ํฌ์ŠคํŒ…์ž…๋‹ˆ๋‹ค. ๋” ์ž์„ธํ•œ ๋‚ด์šฉ์„ ์ฐธ๊ณ ํ•˜์‹œ๋ ค๋ฉด ์•„๋ž˜ ๋‘ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”!

https://www.kodeco.com/21020457-ios-unit-testing-and-ui-testing-tutorial

 

iOS Unit Testing and UI Testing Tutorial

Learn how to add unit tests and UI tests to your iOS apps, and how you can check on your code coverage.

www.kodeco.com

http://yoonbumtae.com/?p=4020 

 

Swift(์Šค์œ„ํ”„ํŠธ): iOS ๋‹จ์œ„ ํ…Œ์ŠคํŠธ(Unit test) ๋ฐ UI ํ…Œ์ŠคํŠธ ํŠœํ† ๋ฆฌ์–ผ - BGSMM

์›๋ฌธ iOS Unit Testing and UI Testing Tutorial   ๋ฒ„์ „ Swift 5, iOS 14, Xcode 12   iOS ๋‹จ์œ„ ํ…Œ์ŠคํŠธ(Unit test) ๋ฐ UI ํ…Œ์ŠคํŠธ ํŠœํ† ๋ฆฌ์–ผ iOS ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” ๊ฑฐ์ฐฝํ•˜์ง€ ์•Š์ง€๋งŒ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ์•ฑ์ด

yoonbumtae.com

 

Tutorial

final class BullsEyeTests: XCTestCase {
  var sut: BullsEyeGame!
}
  • sut๋Š” System Under Test์˜ ์•ฝ์ž๋กœ์„œ ํ…Œ์ŠคํŠธ์— ํ•„์š”ํ•œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•จ

 

  override func setUpWithError() throws {
    try super.setUpWithError()
    sut = BullsEyeGame()
  }

 

  • ๊ฐ ์ •์˜๋œ ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํ–‰๋˜๋ฉด setUpWithError๊ฐ€ ํ˜ธ์ถœ๋˜๋ฏ€๋กœ setUpWithError์—์„œ ํ…Œ์ŠคํŠธ์— ํ•„์š”ํ•œ sut ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ด ์คŒ

 

  override func tearDownWithError() throws {
    sut = nil
    try super.tearDownWithError()
  }
  • ๊ฐ ์ •์˜๋œ ํ…Œ์ŠคํŠธ๊ฐ€ ๋๋‚˜๋ฉด tearDownWithError๊ฐ€ ํ˜ธ์ถœ๋˜๋ฏ€๋กœ tearDownWithError์—์„œ sut๋ฅผ ํ•ด์ง€ํ•ด ์คŒ

 

  func testScoreIsComputedWhenGuessIsHigherThanTarget() {
    // 1. given
    let guess = sut.targetValue + 5

    // 2. when
    sut.check(guess: guess)

    // 3. then
    XCTAssertEqual(sut.scoreRound, 95, "Score computed from guess is wrong")
  }
  • test~ ๋‹จ์–ด๋กœ ์‹œ์ž‘ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•ด์„œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ์คŒ
  • XCAssert๋กœ ๊ฐ’์„ ๋น„๊ตํ•ด์„œ ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ–ˆ๋Š”์ง€ ์‹คํŒจํ–ˆ๋Š”์ง€ ํ™•์ธํ•จ

 

  • ์ฐธ๊ณ : ๊ฐ ์„น์…˜ ์„ค๋ช…
    • given : ํ•„์š”ํ•œ ๊ฐ’ ์„ค์ •
    • when : ํ…Œ์ŠคํŠธ ์ค‘์ธ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•จ
    • then : ์˜ˆ์ƒํ•œ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ์ˆ . XCTestAssertions๋ฅผ ์‚ฌ์šฉ

728x90
๋ฐ˜์‘ํ˜•

'๐ŸŽ iOS' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Unit Test] Test Double  (0) 2023.04.14
[iOS/Swift] ๋น„๋™๊ธฐ(async) ํ…Œ์ŠคํŠธ  (0) 2023.04.14
[iOS/Swift] XCTestCase ์ƒ์„ฑํ•˜๊ธฐ  (0) 2023.04.13
[iOS/Swift] Unit Test ๋ž€?  (0) 2023.04.10
[RxSwift] passing viewmodel data to viewController  (0) 2023.03.25

๋Œ“๊ธ€