Overview
Native mobile accessibility testing spans two complementary layers:
This skill covers both layers on iOS and Android. Full per-platform detail lives in references/ios-audit.md and references/android-checks.md.
Nearest neighbors and differentiation:
When to use
iOS - core audit
performAccessibilityAudit() (iOS 17+) audits the current view and fails the test automatically if any issue is found - no explicit assertion needed (wwdc23 (opens in new window)).
import XCTest
final class HomeAccessibilityTests: XCTestCase {
override func setUpWithError() throws {
continueAfterFailure = true // report ALL issues per screen, not just the first
XCUIApplication().launch()
}
func testHomeScreenAudit() throws {
try XCUIApplication().performAccessibilityAudit()
}
}Scoped audits, false-positive suppression, audit-per-screen, VoiceOver label/trait/hint checks, 44pt touch targets, and Accessibility Inspector are in references/ios-audit.md.
Android - core checks
AccessibilityChecks.enable() fires the Accessibility Test Framework on every Espresso perform() call; setRunChecksFromRootView(true) checks the whole hierarchy, not just the interacted view (atf (opens in new window)). Requires the espresso-accessibility dependency.
import androidx.test.espresso.accessibility.AccessibilityChecks
@RunWith(AndroidJUnit4::class)
class CheckoutAccessibilityTest {
init {
AccessibilityChecks.enable().setRunChecksFromRootView(true)
}
@Test
fun applyPromoCode() {
onView(withId(R.id.promo_field)).perform(typeText("WELCOME10"), closeSoftKeyboard())
onView(withId(R.id.apply_button)).perform(click())
// checks fire automatically on every perform()
}
}The dependency, suppression, 48dp touch targets, contrast thresholds, contentDescription labelling, and the TalkBack manual workflow are in references/android-checks.md.
CI integration
iOS (GitHub Actions)
jobs:
a11y-audit:
runs-on: macos-15
steps:
- uses: actions/checkout@v5
- run: |
xcodebuild test \
-project MyApp.xcodeproj \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15,OS=latest' \
-only-testing MyAppUITests/HomeAccessibilityTests \
-resultBundlePath A11yResults.xcresult
- uses: actions/upload-artifact@v4
if: always()
with:
name: a11y-xcresult
path: A11yResults.xcresultAndroid (GitHub Actions)
jobs:
a11y-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
script: ./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.CheckoutAccessibilityTest
- uses: actions/upload-artifact@v4
if: always()
with:
name: a11y-test-results
path: app/build/outputs/androidTest-resultsAnti-patterns
| Anti-pattern | Why it fails | Fix |
|---|---|---|
continueAfterFailure = false in audit tests | Stops after the first issue; misses the rest on the same screen | Set continueAfterFailure = true for audit tests (wwdc23 (opens in new window)) |
| No suppression closure; globally ignoring an audit type | Hides all failures of that type, not just the known one | Suppress by both auditType and element.label (references/ios-audit.md) |
Setting accessibilityLabel to the element type | "Submit button" - VoiceOver already announces "button" from traits | Set label to purpose only: "Submit order" (uia (opens in new window)) |
contentDescription on every Text composable | Redundant; TalkBack reads text content automatically | Omit for plain text; set only for icon-only or image elements (cd (opens in new window)) |
Running AccessibilityChecks without setRunChecksFromRootView(true) | Checks only the interacted view; off-screen violations pass | Enable root-view mode (Android core, above) (atf (opens in new window)) |
| Manual TalkBack only, no automated checks | Inconsistent; regressions slip in on refactors | Pair TalkBack manual review with AccessibilityChecks in CI |
Limitations
References
Extends the core AccessibilityChecks.enable() example in ../SKILL.md (opens in new window). Checks run automatically on any ViewActions action and cover the acted-on view plus all descendant views (atf (opens in new window)).
Add the dependency
// app/build.gradle
dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.6.1'
}Enable checks from the root view
import androidx.test.espresso.accessibility.AccessibilityChecks
@RunWith(AndroidJUnit4::class)
class CheckoutAccessibilityTest {
init {
AccessibilityChecks.enable().setRunChecksFromRootView(true)
}
@Test
fun applyPromoCode() {
onView(withId(R.id.promo_field)).perform(typeText("WELCOME10"), closeSoftKeyboard())
onView(withId(R.id.apply_button)).perform(click())
// checks fire automatically on every perform()
}
}setRunChecksFromRootView(true) evaluates the whole hierarchy, not just the interacted view (atf (opens in new window)).
Suppress known issues
AccessibilityChecks.enable().apply {
setSuppressingResultMatcher(
allOf(
matchesCheck(TextContrastCheck::class.java),
matchesViews(withId(R.id.decorative_watermark))
)
)
}The matcher must satisfy both the check type and the specific view (atf (opens in new window)).
Touch target size (48dp minimum)
Each interactive UI element should have a focusable area of at least 48dp x 48dp (atgt (opens in new window)). AccessibilityChecks validates this on every perform() call.
Contrast thresholds
AccessibilityChecks (via the Accessibility Test Framework) checks these on every perform() call (contrast (opens in new window)):
contentDescription labelling
Convey purpose, not visual detail (cd (opens in new window)):
// Icon-only button: set contentDescription
Icon(
imageVector = Icons.Filled.Share,
contentDescription = stringResource(R.string.label_share)
)
// Decorative image: suppress from accessibility
Icon(
imageVector = Icons.Filled.Decoration,
contentDescription = null // TalkBack skips this element
)Verify with Espresso:
onView(withId(R.id.share_button))
.check(matches(withContentDescription(R.string.label_share)))TalkBack manual workflow
Enable via Settings > Accessibility > TalkBack > On, then (at (opens in new window)):
Manual checklist:
References
Extends the core performAccessibilityAudit() example in ../SKILL.md (opens in new window). The audit is available from iOS 17 and fails the test automatically when it finds an issue, so no explicit assertion is needed (wwdc23 (opens in new window)).
Scope the audit to specific categories
try app.performAccessibilityAudit(for: [.dynamicType, .contrast])Pass an XCUIAccessibilityAuditType option set. Documented audit types include .dynamicType and .contrast; passing no argument runs all available checks (wwdc23 (opens in new window)).
Suppress known false positives
try app.performAccessibilityAudit(for: [.contrast]) { issue in
// Ignore the decorative watermark label (no contrast fix planned)
if let element = issue.element,
element.label == "WatermarkLabel",
issue.auditType == .contrast {
return true // suppress this issue
}
return false
}The closure receives an XCUIAccessibilityAuditIssue; return true to suppress. Narrow suppressions by both auditType and element.label so real regressions still fail (wwdc23 (opens in new window)).
Cover each screen
Each call inspects only the currently visible elements. Navigate to every distinct screen and re-run the audit:
func testCheckoutFlowAudit() throws {
let app = XCUIApplication()
app.launch()
try app.performAccessibilityAudit() // Screen 1
app.buttons["place-order-button"].tap()
try app.performAccessibilityAudit() // Screen 2
}VoiceOver label, trait, and hint checks
accessibilityLabel is the localized string VoiceOver reads to identify an element, accessibilityHint describes the action result, and accessibilityTraits communicates purpose - common values are .button, .link, .header, .image, .staticText, .adjustable (uia (opens in new window)). Production code sets them; XCUITest verifies via XCUIElement.label:
// Production (UIKit)
let submitButton = UIButton()
submitButton.accessibilityLabel = "Submit order"
submitButton.accessibilityHint = "Places your order and charges the saved card"
submitButton.accessibilityTraits = [.button]// Test
func testSubmitButtonLabel() {
let btn = XCUIApplication().buttons["Submit order"]
XCTAssertTrue(btn.exists, "VoiceOver cannot find the Submit button")
XCTAssertEqual(btn.label, "Submit order")
}Touch target size (44pt minimum)
The minimum control size on iOS and iPadOS is 44x44 pt (hig (opens in new window)). Assert via XCUIElement.frame:
func testSubmitButtonTouchTarget() {
let frame = XCUIApplication().buttons["Submit order"].frame
XCTAssertGreaterThanOrEqual(frame.width, 44, "Touch target width below 44pt")
XCTAssertGreaterThanOrEqual(frame.height, 44, "Touch target height below 44pt")
}Accessibility Inspector (manual complement)
Open it from Xcode menu > Open Developer Tool > Accessibility Inspector. It runs the same checks as performAccessibilityAudit() interactively on real devices and simulators - use it to diagnose an audit failure before writing a suppression (wwdc23 (opens in new window)).