티스토리 뷰

iOS/Test

테스트 기초 - UI TEST

@서비 2022. 4. 20. 00:05

1. 설정

내비게이션 바에서 6번 째로 이동해서 UI Test target 추가해 준다.

UI Test Target 추가

 

 

2. 튜토리얼 확인

UIView 상의 Object에 접근하는 방법이 Xcode 와는 다르기 때문에 그 부분을 먼저 확인해야 한다.

그리고 사용자의 액션이 추가가 되면 그부분에 대한 명령 도 일아 야 한다.

 

app.buttons["Button"].tap()

위와 같은 문구에 대해 설명하자면,

app   //app = XCUIApplication() 로 코드에서 할당하였다 app 앱의

buttons["Button"]  //Button이라는 버튼을

tap()  //탭 하라는 동작이다.

 

다 외울 수 없기 때문에 쉽게 확인 하는 방법이 있다.

소스코드 왼쪽 하단의 빨간색 녹화 버튼을 누르고 나서 시뮬레이터 안의 버튼을 선택하는 동작 등을 하면 Xcode에 시스템이 코드로 작성해 준다. 그러면 그 코드를 활용하면 된다.

 

녹화 버튼

3. 프로그램 코드 작성

Button 이라는 버튼을 탭 하고 해당 버튼이 샐렉티드로 바뀌는지 보는 테스트 코드를 작성해 보았다.

테스트 코드는 동작시키는 방법에 따라 다른 형태로도 작성이 가능하다.

import XCTest

class ActiveLabelTestUITests: XCTestCase {

    var app: XCUIApplication!

    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.

        // In UI tests it is usually best to stop immediately when a failure occurs.
        try super.setUpWithError()
        continueAfterFailure = false
        app = XCUIApplication()
        app.launch()

        // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
    }

    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func testViewcontrollerButtonClicked() throws{
     
            
        //ACT
        app.buttons["Button"].tap()


        //ASSERT
        XCTAssertFalse(app.buttons["Button"].isSelected,"테스트 실패")
    }

 

 

정리 :  우선적으로 테스트 함수를 따로 둘 수 있는 기능은 좋은 거 같다. 혹시라도 함수를 계속 수정하거나 UI를 계속 수정할 때는 약간 애매 하지 않을 까 하는 생각이 들었다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
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
글 보관함