Frontend 2,814 installs

Writing Flutter Widget Tests

by flutter/skills

Implement a component-level test using `WidgetTester` to verify UI rendering and user interactions (tapping, scrolling, entering text). Use when validating…

Skill content

Writing Flutter Widget Tests

Contents

- Setup & Configuration

- Core Components

- Workflow: Implementing a Widget Test

- Interaction & State Management

- Examples

Setup & Configuration

Ensure the testing environment is properly configured before authoring widget tests.

- Add the flutter_test dependency to the dev_dependencies section of pubspec.yaml.

- Place all test files in the test/ directory at the root of the project.

- Suffix all test file names with _test.dart (e.g., widget_test.dart).

Core Components

Utilize the following flutter_test components to interact with and validate the widget tree: