본문 바로가기
IT/android

#3 나만 헷갈렸나? Jackpot Compose > 스크롤, 여백, 키보드, 계측 테스트

by 내일은교양왕 2025. 5. 16.


가로모드 지원. 스크롤 가능하게

자동으로 가로모드가 지원되지만 스크롤은 안된다.

최상위 컴포저블의 modifier에서 아래의 코드 추가

  verticalScroll(rememberScrollState())

 

 

여백 설정

Modifier  설명
statusBarsPadding() 상단(status bar) 높이만큼 padding
safeDrawingPadding() 상단 + 하단 + 양옆 등 모든 시스템 UI를 고려해서 안전한 padding

 

asis tobe

 

 

KeyboardOptions

속성 키보드의 작업버튼
ImeAction.Search
ImeAction.Send
ImeAction.Go

 

 

계측테스트 (Implementation test)

Web 개발자로 치자면 e2e 테스트라고 보면 된다. 예) cypress

테스트 코드로 자동으로 적절한 노드를 선택해 값을 입력하고 결과를 확인하는 방식

테스트 실행 하면 실제 에뮬레이터를 띄운 후 TC가 돌아간다  (cypress도 마찬가지)

 

만드는 순서

  1. project view 에서 src 디렉토리 기준으로 /androidTest/java 디렉토리를 만든다
  2. main과 똑같은 package 구조를 만든다. 예) com.example.tiptime
  3. 해당 package에서 TipUITest class 생성
class TipUITests {
    @get:Rule
    val composeTestRule = createComposeRule() // MainActivity.kt파일의 onCreate()처럼 동작하기 위해

    @Test
    fun calculate_20_percent_tip() {
        composeTestRule.setContent {
            TipTimeTheme {
                TipTimeLayout()
            }
        }
        composeTestRule.onNodeWithText("Bill Amount").performTextInput("10")
        composeTestRule.onNodeWithText("Tip Percentage").performTextInput("20")
        val expectedTip = NumberFormat.getCurrencyInstance().format(2)
        composeTestRule.onNodeWithText("Tip Amount: $expectedTip").assertExists(
            "No node with this text was found."
        )
    }
}