Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Mobile Application Accessibility Testing: Automating With Espresso and XCTest Frameworks

DZone's Guide to

Mobile Application Accessibility Testing: Automating With Espresso and XCTest Frameworks

Accessibility of mobile apps has been getting more attention. Learn how to use Espresso and XCUITest for mobile app accessibility testing.

· Mobile Zone ·
Free Resource

Why Is Accessibility Testing Important?

Last year, Apple CEO Tim Cook expressed the growing need to make all types of applications – web and mobile – accessible to everyone:

"We've always viewed accessibility as a human right, and just like human rights are for everyone, we want our products to be accessible to everyone." -Tim Cook

Websites frequently have been targets of disability discrimination and, unfortunately, this trend is making its way into the domain of mobile applications.

Leverage Instrumented Tests (Espresso & XCUITest) for Accessibility Testing

Espresso users can use their existing tests to run and validate accessibility issues; with a few minor changes, the same test artifacts can help developers find these types of issues early in the process.

The AccessibilityCheck class runs accessibility checks automatically before any interaction with a View. Just import the class and add the following code to your setup methods annotated with @Before:

import android.support.test.espresso.contrib.AccessibilityChecks;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AccessibilityChecksIntegrationTest {
 @BeforeClass
 public static void enableAccessibilityChecks() {
  AccessibilityChecks.enable();
 }
}

To learn more about this technique, check out https://developer.android.com/training/testing/espresso/accessibility-checking

iOS developers can take advantage of Google's GTXiLib, an open-source accessibility test automation framework. GTXiLib is based on the XCTest unit testing framework. You can install GTXiLib for any of your test classes and register a number of accessibility checks to be performed along with your unit tests. If any accessibility check fails, the corresponding unit test will also fail.

To install GTXiLib for one of your test classes, just add the following line of code to its +setup method:

+(void) setUp {
 [super setUp];
 // ... your other setup code (if any) comes here.
 // Install GTX on all tests in *this* test class.
 [GTXiLib installOnTestSuite: [GTXTestSuite suiteWithAllTestsInClass: self]
  checks: [GTXChecksCollection allGTXChecks]
  elementBlacklists: @[]
 ];
}

Using this method, all accessibility checks will be run for each of the unit tests defined in that test class.

For more GTXiLib tips and info, take a look at GTXiLib on GitHub.

We Can Make Accessibility Testing Easier

Perfecto has advanced support for Espresso and XCUITests which allows users to combine the power of these test assets with the cloud. Our support for these frameworks enables development teams to retain the advantages discussed above while adding the security, flexibility, and robustness of Perfecto’s cloud-based platform.

To learn more about the Perfecto solution.

Better Software Can Make a Difference

Most aspects of mobile accessibility are covered in existing W3C WAI accessibility standards/guidelines. At this time, however, there are no separate guidelines for mobile accessibility; the W3C is developing updated requirements and more specific guidance regarding this important issue.

Ensuring a great user experience for everyone doesn’t have to be a chore- the tools we’ve talked about here will help get your testing strategy on the right track. Accessibility is something all companies and developers should be thinking about. It’s just the right thing to do.

As Tim Cook put it, “We don’t make products for a particular group of people; we make products for everybody.  We feel very strongly that everyone deserves an equal opportunity and equal access.”

Topics:
mobile ,accessibility ,mobile app development ,test automation ,espresso ,xctest

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}