Notice
Recent Posts
Recent Comments
Link
ยซ   2024/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

lgvv98

part5 (ch6) UI Test ๋ณธ๋ฌธ

โš ๏ธ deprecated โš ๏ธ/ํŒจ์บ (์ดˆ๊ฒฉ์ฐจ)

part5 (ch6) UI Test

๐Ÿฅ• ์บ๋Ÿฟ๋งจ 2022. 2. 1. 10:42

โœ… ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” UI Test์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณผ ์˜ˆ์ •์ด์•ผ.

 

์œ ๋‹› ํ…Œ์ŠคํŠธ์™€ UI ํ…Œ์ŠคํŠธ์˜ ์ฐจ์ด

์ฐจ์ด์ !

 

์œ ๋‹› ํ…Œ์ŠคํŠธ๋Š” ํด๋ž˜์Šค์— ๋Œ€ํ•ด์„œ ์ง„ํ–‰ํ•˜๊ณ , UI ํ…Œ์ŠคํŠธ๋Š” ์•ฑ ์ž์ฒด๋ฅผ ๋Ÿฐ์น˜ ์‹œ์ผœ์„œ ์‚ฌ์šฉํ•œ๋‹ค.

 

XCUIApplication์„ ๋ฌธ์„œ์—์„œ ์‚ดํŽด๋ณด๋ฉด ํ•˜๋‚˜์˜ ํด๋ž˜์Šค์ด๋‹ค!

 

Xcode ํ•˜๋‹จ์— ๋นจ๊ฐ„ ๋…นํ™”๋ฒ„ํŠผ

 

๋…นํ™”๋ฒ„ํŠผ์„ ์ด์šฉํ•ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ๋‹ค. 

๋‹ค๋งŒ, ๋„คํŠธ์›Œํฌ๊ฐ€ ์žˆ์–ด์•ผ ํ•˜๊ฑฐ๋‚˜, ์—ฌ๋Ÿฌ๋ฒˆ์˜ ํƒญ์„ ํ†ตํ•ด ์ด๋™ํ•œ ํ™”๋ฉด ๋“ฑ ์–ด๋ ค์›€์ด ์กด์žฌํ•˜์—ฌ, Unit Test๋ฅผ ๋” ํ™œ์šฉํ•œ๋‹ค.

 

๋˜ํ•œ ๋…นํ™” ๋ฒ„ํŠผ์„ ํ†ตํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•ด์•ผํ•˜๋Š”์ง€ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•˜์ž.

 

๐ŸŸ  ์•„๋ž˜๋Š” ์˜ˆ์‹œ์ฝ”๋“œ

//
//  MovieReviewUITests.swift
//  MovieReviewUITests
//
//  Created by Hamlit Jason on 2022/01/17.
//

import XCTest

// UITest์˜ ๊ฒฝ์šฐ์—๋Š” ํ˜„์—…์—์„œ๋Š” ๋„คํŠธ์›Œํฌ์— ์—ฐ๊ฒฐ๋˜์–ด์žˆ์–ด์•ผ ์•ฑ์ด ๊ตฌ๋™๋˜๋Š”์ , ๋˜ํ•œ, ์—ฌ๋Ÿฌ๋ฒˆ ํด๋ฆญํ•ด์„œ ๊ทธ ์ง€์ ์œผ๋กœ ๊ฐ€์„œ ์‚ฌ์šฉํ•ด์•ผํ•˜๋Š” ๋‹จ์ ์œผ๋กœ ์ธํ•ด Unitํ…Œ์ŠคํŠธ๋งŒ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.
class MovieReviewUITests: XCTestCase {

    var app: XCUIApplication!
    
    override func setUp() {
        super.setUp()
        
        continueAfterFailure = false // ์‹คํŒจํ•˜๋ฉด ์ฝ”๋“œ ์ญ‰ ์‹คํ–‰์•ˆํ•˜๊ณ  ์ข…๋ฃŒ
        
        app = XCUIApplication()
        app.launch()
    }
    
    override func tearDown() {
        super.tearDown()
        
        app = nil
    }
    
    func test_navigationBar์˜_ํƒ€์ดํ‹€์ด_์˜ํ™”ํ‰์ ์œผ๋กœ_์„ค์ •๋˜์–ด์žˆ๋‹ค() {
        let existNavigationBar = app.navigationBars["์˜ํ™” ํ‰์ "].exists
        XCTAssertTrue(existNavigationBar)
    }
    
    func test_SearchBar๊ฐ€_์กด์žฌํ•œ๋‹ค() {
        // ์„œ์น˜๋ฐ”๊ฐ€ ๋„ค๋น„๊ฒŒ์ด์…˜์˜ ์„œ์น˜ํ•„๋“œ์— ๋“ค์–ด์žˆ๊ธฐ ๋•Œ๋ฌธ์—
        let existSearchBar = app.navigationBars["์˜ํ™” ํ‰์ "]
            .searchFields["Search"]
            .exists
        XCTAssertTrue(existSearchBar)
    }
    
    func test_SearchBar์—_cancel๋ฒ„ํŠผ์ด_์กด์žฌํ•œ๋‹ค() {
        let navigationBar = app.navigationBars
        navigationBar
            .searchFields["Search"]
            .tap()
        
        let existSearchBarCancelButton = navigationBar
            .buttons["Cancel"]
            .exists
        
        XCTAssertTrue(existSearchBarCancelButton)
    }
    
    func test_๋…นํ™”๋ฒ„ํŠผ์„_ํด๋ฆญํ•ด์„œ_ํ…Œ์ŠคํŠธ์ฝ”๋“œ_์ž‘์„ฑ() {
        let app = XCUIApplication()
        let navigationBar = app.navigationBars["์˜ํ™” ํ‰์ "]
        let searchSearchField = navigationBar.searchFields["Search"]
        searchSearchField.tap()
        app.tables["Empty list"].swipeUp()
        searchSearchField.swipeDown()
        navigationBar.buttons["Cancel"].tap()
        
        let collectionViewsQuery = app.collectionViews
        collectionViewsQuery.children(matching: .cell).element(boundBy: 3).swipeUp()
        collectionViewsQuery.children(matching: .cell).element(boundBy: 2).swipeDown()
    }
    
}
Comments