An introduction to widget testing - Flutter In the introduction to unit testing recipe, you learned how to test Dart classes using the test package To test widget classes, you need a few additional tools provided by the flutter_test package, which ships with the Flutter SDK The flutter_test package provides the following tools for testing widgets: The WidgetTester allows building and interacting with widgets in a test environment The
Testing Flutter apps Widget tests A widget test (in other UI frameworks referred to as component test) tests a single widget The goal of a widget test is to verify that the widget's UI looks and interacts as expected Testing a widget involves multiple classes and requires a test environment that provides the appropriate widget lifecycle context
Flutter > How to handle scrolling in a widget test Many apps feature lists of content, from email clients to music apps and beyond To verify that lists contain the expected content using widget tests, you need a way to scroll through lists to search for particular items To scroll through lists via integration tests, use the methods provided by the [`WidgetTester`][] class, which is included in the
Tap, drag, and enter text - Flutter In the test environment, Flutter doesn't automatically rebuild widgets when the state changes To ensure that the widget tree is rebuilt after simulating a user interaction, call the pump() or pumpAndSettle() methods provided by the WidgetTester This recipe uses the following steps: Create a widget to test Enter text in the text field
Handle scrolling - Flutter How to handle scrolling in a widget test Now, you can write a test In this example, scroll through the list of items and verify that a particular item exists in the list The WidgetTester class provides the scrollUntilVisible() method, which scrolls through a list until a specific widget is visible This is useful because the height of the items in the list can change depending on the device
Accessibility testing - Flutter Testing accessibility on mobile Test your app using Flutter's Accessibility Guideline API This API checks if your app's UI meets Flutter's accessibility recommendations These cover recommendations for text contrast, target size, and target labels The following snippet shows how to use the Guideline API on a sample widget named AccessibleApp:
Find widgets - Flutter During a flutter run session on a widget test, you can also interactively tap parts of the screen for the Flutter tool to print the suggested Finder This recipe looks at the find constant provided by the flutter_test package, and demonstrates how to work with some of the Finders it provides
User input accessibility - Flutter A truly adaptive app also handles differences in how user input works and also programs to help folks with accessibility issues
Visual Studio Code - Flutter Flutter Property Editor The Flutter Property Editor is a powerful tool provided by the Flutter extension that lets you view and modify widget properties directly from its visual interface