티스토리 뷰
1. 설정
내비게이션 바에서 6번 째로 이동해서 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를 계속 수정할 때는 약간 애매 하지 않을 까 하는 생각이 들었다.
'iOS > Test' 카테고리의 다른 글
테스트 응용 - 비 동기 실행 (0) | 2022.08.09 |
---|---|
테스트 응용 - ScreenShot (XCUIScreen, XCTAttechment) (0) | 2022.08.08 |
테스트 팁 - 스크립트로 빌드와 테스트 동시에 하기 (0) | 2022.07.28 |
테스트 팁 - 시뮬레이터 추가 iphone se (1st) (0) | 2022.07.27 |
테스트 기초 - UNIT TEST (0) | 2022.04.18 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- XCTestExpectation
- ios
- CI/CD
- xcode whitespace trim option
- RxSwift
- MQTT
- geohash
- swift
- 코테
- firebase
- bitrise
- AppThinning
- Default Rules
- ChatGPT
- AWS IoT
- Moya
- IF (KAKAO) DEV 2022
- 무료는 아니지만
- swiftLint
- chatgpt 4o
- GPT4
- 모듏화
- 같이쓰기
- async
- 프로그래머스
- ATS failed system trust
- Fastlane
- 빌드자동화
- GCD
- jenkins
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함