테스트
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
접근성을 테스트하는 데 필수적인 방법은 수동 테스트의 한 형태로, TalkBack 또는 스위치 액세스와 같은 접근성 서비스를 사용 설정하고 모든 것이 예상대로 작동하는지 확인하는 것입니다. 이를 통해 접근성 기능이 필요한 사용자가 애플리케이션을 어떻게 경험할 수 있는지 직접적인 통계를 얻을 수 있습니다.
수동 확인과 함께 자동 테스트를 사용하여 앱을 지속적으로 변경할 때 사용자 환경에 영향을 줄 수 있는 잠재적 문제를 신고해야 합니다.
기존 Compose 테스트 API를 사용하면 시맨틱 요소와 상호작용하고 UI에 정의된 속성을 어설션하는 자동 테스트를 작성할 수 있습니다.
접근성 검사
자동 접근성 테스트의 경우 Compose 1.8.0부터 Espresso의 접근성 스캐너 및 접근성 검사를 지원하는 동일한 기본 프레임워크인 접근성 테스트 프레임워크를 사용하여 일부 접근성 관련 검사를 자동으로 실행할 수도 있습니다.
검사를 사용 설정하려면 ui-test-junit4-accessibility
종속 항목을 추가하고 AndroidComposeTestRule
에서 enableAccessibilityChecks()
를 호출한 다음 작업 또는 tryPerformAccessibilityChecks
를 트리거합니다.
@Rule
@JvmField
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
@Test
fun noAccessibilityLabel() {
composeTestRule.setContent {
Box(
modifier = Modifier
.size(50.dp, 50.dp)
.background(color = Color.Gray)
.clickable { }
.semantics {
contentDescription = ""
}
)
}
composeTestRule.enableAccessibilityChecks()
// Any action (such as performClick) will perform accessibility checks too:
composeTestRule.onRoot().tryPerformAccessibilityChecks()
}
이 특정 테스트는 예외와 함께 실패하며 항목에 접근성 서비스에서 읽을 수 있는 라벨이 없을 수 있다는 메시지가 표시됩니다.
사용 가능한 다른 검사는 색상 대비, 작은 터치 영역 크기 또는 요소의 순회 순서와 관련된 접근성 문제를 찾습니다.
뷰와 Compose를 혼합하고 이미 AccessibilityValidator
를 사용 중이거나 구성해야 하는 경우 규칙에서 설정할 수 있습니다.
@Test
fun lowContrastScreen() {
composeTestRule.setContent {
Box(
modifier = Modifier
.fillMaxSize()
.background(color = Color(0xFFFAFBFC)),
contentAlignment = Alignment.Center
) {
Text(text = "Hello", color = Color(0xFFB0B1B2))
}
}
// Optionally, set AccessibilityValidator manually
val accessibilityValidator = AccessibilityValidator()
.setThrowExceptionFor(
AccessibilityCheckResult.AccessibilityCheckResultType.WARNING
)
composeTestRule.enableAccessibilityChecks(accessibilityValidator)
composeTestRule.onRoot().tryPerformAccessibilityChecks()
}
Compose API와 접근성 테스트 프레임워크를 모두 사용하는 자동화 테스트를 수동 테스트와 함께 사용하면 개발 프로세스 초기에 발생할 수 있는 문제를 감지하는 데 도움이 됩니다.
추천 서비스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-27(UTC)"],[],[],null,["An essential way of testing accessibility is a form of manual testing: by\nturning accessibility services, like TalkBack or Switch Access, on, and checking\nif everything works as expected. This provides direct insight into how users\nwith accessibility needs might experience your application.\n\nIn conjunction with manual verification, you should also use automated testing\nto flag any potential issues that could impact user experience as you make\ncontinual changes to your app.\n\n[Existing Compose testing APIs](/develop/ui/compose/testing) allow you to write automated tests that\ninteract with semantic elements and to [assert the properties](/develop/ui/compose/testing/apis#assertions) defined in\nyour UI.\n\nAccessibility checks\n\nFor automated accessibility testing, you can also use the\n[Accessibility Test Framework](https://github.com/google/Accessibility-Test-Framework-for-Android)---the same underlying framework that powers\nAccessibility Scanner and accessibility checks in Espresso---to perform some\naccessibility-related checks automatically, starting with Compose 1.8.0.\n\nTo enable the checks, add the `ui-test-junit4-accessibility` dependency,\ncall [`enableAccessibilityChecks()`](/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#(androidx.compose.ui.test.ComposeUiTest).enableAccessibilityChecks(com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityValidator)) in the [`AndroidComposeTestRule`](/reference/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule),\nand trigger an action or [`tryPerformAccessibilityChecks`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/Actions.android.kt;drc=808c430f1ac6028d33902e3d685720f2b96f7aee;l=27):\n\n\n```kotlin\n@Rule\n@JvmField\nval composeTestRule = createAndroidComposeRule\u003cComponentActivity\u003e()\n\n@Test\nfun noAccessibilityLabel() {\n composeTestRule.setContent {\n Box(\n modifier = Modifier\n .size(50.dp, 50.dp)\n .background(color = Color.Gray)\n .clickable { }\n .semantics {\n contentDescription = \"\"\n }\n )\n }\n\n composeTestRule.enableAccessibilityChecks()\n\n // Any action (such as performClick) will perform accessibility checks too:\n composeTestRule.onRoot().tryPerformAccessibilityChecks()\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/androidTest/java/com/example/compose/snippets/accessibility/AccessibilitySnippets.kt#L49-L71\n```\n\n\u003cbr /\u003e\n\nThis specific test fails with an exception and a message that the item may not\nhave a label readable by accessibility services.\n\nOther available checks look for accessibility issues with color contrast,\nsmall touch target size, or elements' traversal order.\n\nIf you're mixing Views with Compose and you're already using an\n`AccessibilityValidator`, or you need to configure one, you can set it in the\nrule:\n\n\n```kotlin\n@Test\nfun lowContrastScreen() {\n composeTestRule.setContent {\n Box(\n modifier = Modifier\n .fillMaxSize()\n .background(color = Color(0xFFFAFBFC)),\n contentAlignment = Alignment.Center\n ) {\n Text(text = \"Hello\", color = Color(0xFFB0B1B2))\n }\n }\n\n // Optionally, set AccessibilityValidator manually\n val accessibilityValidator = AccessibilityValidator()\n .setThrowExceptionFor(\n AccessibilityCheckResult.AccessibilityCheckResultType.WARNING\n )\n\n composeTestRule.enableAccessibilityChecks(accessibilityValidator)\n\n composeTestRule.onRoot().tryPerformAccessibilityChecks()\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/androidTest/java/com/example/compose/snippets/accessibility/AccessibilitySnippets.kt#L94-L116\n```\n\n\u003cbr /\u003e\n\nIn combination with manual testing, automated tests using both Compose APIs as\nwell as the Accessibility Test Framework can help you detect possible problems\nearly on in the development process.\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Accessibility in Compose](/develop/ui/compose/testing)\n- \\[Material Design 2 in Compose\\]\\[19\\]\n- [Testing your Compose layout](/develop/ui/compose/testing/apis#assertions)"]]