Automated accessibility tests kit for Android apps (AATK)

This library consists of a collection of automated accessibility tests designed to run with Robolectric. This enables them to be executed as local tests, without the need for a physical or emulated device..

These tests were developed with a focus on the most common accessibility issues and the most frequently used widgets, where many accessibility problems tend to arise. It’s important to note that these automated tests do not replace the need for manual checks and verifications.

Installation

To use AATK in your Android project, follow these steps:

  1. Add it in the settings.gradle at the end of repositories.
    allprojects {
      repositories {
       ...
       maven { url 'https://jitpack.io' }
      }
    }
    
  2. Configure your app-level build.gradle file for Robolectric and AATK testing by updating the testOptions and adding the necessary dependencies. After making these changes, sync your project to ensure they take effect.
android{
    ...
    testOptions {
        // Used for Unit testing Android dependent elements in test folder
        unitTests.includeAndroidResources  = true
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    ...
    testImplementation 'org.robolectric:robolectric:4.9'
    testImplementation 'com.github.AALT-Framework:android-accessibility-test-kit:v1.0.0-alpha'
    ...
}

Usage

Create your own Java Test File class and set up like this:

@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
    private View rootView;
    private AccessibilityTestRunner runner;

    @Rule
    public ErrorCollector collector = new ErrorCollector();

    @Before
    public void setUp() {
        Activity activity = Robolectric.buildActivity(MyActivity.class).create().get();

        // Get the root node of the view hierarchy
        rootView = activity.getWindow().getDecorView().getRootView();
        runner = new AccessibilityTestRunner(collector);
    }
}

Then, write your test. For example, to test contrast ratio:

  @Test
  public void mustUseAdequateContrastRatio(){
    runner.runAccessibilityTest(rootView, new TestAdequateContrastRatio());
  }

Tests available

Currently, this kit performs the following checks:

TestTest Class NameDescription
Color contrastTestAdequateContrastRatioA contrast ratio of at least 4.5:1 should be used
SpacingTestInteractionElementSpacingInteraction components should have a minimum spacing of 8dp
Component labelTestMustFormControlHaveLabelForm controls must have and associated label
Alternative textTestMustHaveAlternativeTextAll non-textual content must have an alternative text description
Touch target sizeTestTouchTargetSizeAll interaction elements should have a minimum of 48x48dp

Visit the test description page for more information.

Contributing

Contributions to this library are welcome. If you find any bugs or issues, please feel free to open an issue or submit a pull request.

The kit of tests is quickly extensible. A list of accessibility issues to be addressed can be found here.