Dart testing
Skip to main content asterisk Overview docs Docs newsmode Blog public Community play_lesson Learn Dart download Get Dart Introduction Variables Operators Comments Built-in types Records Collections Generics Typedefs Type system Overview & usage Pattern types Applied tutorial open_in_new Loops Branches Error handling Functions Metadata Libraries & imports Classes Constructors Primary constructors Methods Extend a class Mixins Enums Dot shorthands Extension methods Extension types Callable objects Overview & usage Class modifiers for API maintainers Reference Overview Asynchronous programming Isolates Sound null safety Understanding null safety Dart keywords Language versioning Overview dart:core dart:async dart:math dart:convert dart:io dart:js_interop Iterable collections Tutorial Futures and error handling Using streams Creating streams Overview Style Documentation Usage Design How to use packages Creating packages Distributing CLI tools Publishing packages Data-driven fixes Writing package pages Workspaces (monorepo support) Hooks Ship skills with packages Dependencies Package layout conventions Pub environment variables Pubspec file Troubleshooting pub Verified publishers Security advisories Versioning Custom package repositories What not to commit Commonly used packages Dart team packages JSON serialization Number representation Google APIs Multi-platform apps Overview Fetch data from the internet Libraries & packages Google Cloud Overview Get started Deployment Libraries & packages Wasm compilation Environment declarations Overview C interop Objective-C & Swift interop Java & Kotlin interop Overview Usage JS types Tutorials Past JS interop Web interop Overview IntelliJ & Android Studio VS Code Troubleshoot analyzer performance Dart DevTools Overview Troubleshooting DartPad Overview dart dart analyze dart build dart compile dart create dart doc dart fix dart format dart info dart install dart migrate dart pub dart run dart test dartaotruntime Experiment flags build_runner package:skills webdev Customizing static analysis Fixing type promotion failures Linter rules Analyzer plugins Diagnostic messages Testing Debugging web apps Overview Tutorial Overview Package skills Dart and Flutter MCP server open_in_new Genkit Dart open_in_new Dart Blog Changelog What's new in the docs Language cheatsheet Language specification Dart 3 migration guide Glossary Books Videos open_in_new API reference open_in_new DartPad (online editor) open_in_new Flutter open_in_new Package site open_in_new vertical_align_top Dart testing Dart 3.14 brings your workflow full circle with automated SDK migrations (dart migrate), a re-engineered DartPad, and faster WebAssembly.
Learn more Software testing, an important part of app development, helps verify that your app is working correctly before you release it. This Dart testing guide outlines several types of testing, and points you to where you can learn how to test your Flutter , web , and server-side apps and scripts . You can run tests on the command line using the dart test command (or, for Flutter apps, flutter test ). Kinds of testing # The Dart testing docs focus on three kinds of testing, out of the many kinds of testing that you might be familiar with: unit, component, and end-to-end (a form of integration testing).
Testing terminology varies, but these are the terms and concepts that you are likely to encounter when using Dart technologies: Unit tests focus on verifying the smallest piece of testable software, such as a function, method, or class. Your test suites should have more unit tests than other kinds of tests. Component tests (called widget tests in Flutter) verify that a component (which usually consists of multiple classes) behaves as expected.
A component test often requires the use of mock objects that can mimic user actions, events, perform layout, and instantiate child components. Integration and end-to-end tests verify the behavior of an entire app, or a large chunk of an app. An integration test generally runs on a simulated or real device or on a browser (for the web) and consists of two pieces: the app itself, and the test app that puts the app through its paces.
An integration test often measures performance, so the test app generally runs on a different device or OS than the app being tested. Generally useful libraries # Although your tests partly depend on the platform your code is intended for—Flutter, the web, or server-side, for example—the following packages are useful across Dart platforms: package:test Provides a standard way of writing tests in Dart. You can use the test package to: Write single tests, or groups of tests.
Use the @TestOn annotation to restrict tests to run on specific environments. Write asynchronous tests just as you would write synchronous tests. Tag tests using the @Tag annotation. For example, define a tag to create a custom configuration for some tests, or to identify some tests as needing more time to complete. Create a dart_test.yaml file to configure tagged tests across multiple files or an entire package. package:mockito Provides a way to create mock objects, easily configured for use in fixed scenarios, and to verify that the system under test interacts with the mock object in expected ways.
For an example that uses both package:test and package:mockito, see the International Space Station API library and its unit tests in the mockito package . Flutter testing # Use the following resources to learn more about testing Flutter apps: Testing Flutter Apps How to perform unit, widget, or integration tests on a Flutter app. flutter_test A testing library for Flutter built on top of package:test. flutter_driver A testing library for testing Flutter applications on real devices and emulators (in a separate process). flutter_gallery Source code and tests for the Flutter gallery example. flutter/dev/manual_tests Many examples of tests in the Flutter SDK.
Other tools and resources # You might also find the following resources useful for developing and debugging Dart applications. IDE # When it comes to debugging, your first line of defense is your IDE. Dart plugins exist for many commonly used IDEs . Dart DevTools # Dart DevTools is a suite of performance tools for Dart and Flutter. For details, see the Dart DevTools documentation. Continuous integration # Consider using continuous integration (CI) to build your project and run its tests after every commit.
Two CI services for GitHub are GitHub Actions and AppVeyor . Learn more about GitHub Actions: Many packages provided by the Dart team use GitHub Actions. For an example, see markdown.yaml in the markdown package's repo. To see how that repo migrated from Travis CI to GitHub Actions, look at PR #353 . Was this page's content helpful? Unless stated otherwise, the documentation on this site reflects Dart 3.14.0. Page last updated on 2026-05-15.
View source or report an issue .