Approaches for Automated Testing
For any component, there are multiple types of automated tests that could apply. There’s unit testing for isolated logic and functionality, component testing for a single component or a group of components, integration testing for compound components or pages, and end-to-end testing for whole pages.
But these lines are blurry. In my opinion, you should use the automated tooling that helps you reproduce bugs and ensures fixes are baked in. What you call it is less important.
Linting
Linters are helpful for checking code before you commit it, but you might need to configure them to keep the tools helpful.
Unit tests
Unit tests can be helpful for internal component APIs and logic. These tests shouldn’t interface with outside functions or other components.
Accessibility unit tests can assert component-specific behavior, interaction/focus APIs, the presence of text alternatives, and ARIA states.
I consider these three unit testing tools (Jest, Testing Library, and Jest-DOM) to be essential for any modern web app if you can make it work with their various plugins.
Component testing
Integration testing
After unit testing, integration testing is the next big leap. Both integration and end-to-end testing can assert more real-world browser testing, document/page-level rules, widget interoperability, and color contrast. They also offer more flexible framework testing options.
End-to-End testing
End-to-End testing, or e2e, covers whole pages. This allows for unique accessibility testing aspects such as page navigation and page-level issues like visual contrast or document language.
End-to-end testing isn’t necessarily distinct from integration in my experience. You also wouldn’t want to drown in testing tools just to satisfy some semantic purpose. The goal with end-to-end and integration testing is to cover the page context, and any details you can’t assert with unit tests (like link clicks actually going to a new page).
Let us appreciate these GIF metaphors. Unit tests (opens in a new tab) and Integration tests (opens in a new tab)
Configuring Testing Tools
Tool configuration can be challenging! Sometimes infrastructure changes can cause blocking issues that require a pivot: “Can these upgrades wait? Until when, and what will we do in the meantime?”
Here are some questions to ask while configuring tooling:
- How is the UI in your app rendered? React-DOM, React-Native, Angular, etc.?
- Can you inject tooling for accessibility tests in that context?
- i.e., can you inject Axe into the target document or environment?
- How is the code bundled?
- Does it use webpack, Parcel, etc.?
- Can you make changes to the infrastructure for accessibility testing, or will you have to make do with what’s already there? (i.e. Testing Library userEvent)
- Who do I have to talk to to get a configuration change around here? 😏
Links
- https://jestjs.io/ (opens in a new tab)
- https://testing-library.com/ (opens in a new tab)
- https://github.com/testing-library/jest-dom (opens in a new tab)
- https://docs.cypress.io/guides/component-testing/overview (opens in a new tab)
- https://storybook.js.org/ (opens in a new tab)
- https://cypress.io (opens in a new tab)
- https://webdriver.io/ (opens in a new tab)