OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add dart-lang/skills --skill dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
npx skills add dart-lang/skills --skill dart-add-unit-test
Organize test files to mirror the lib directory structure to maintain predictability.
test directory at the root of the package._test.dart to the end of all test file names (e.g., lib/src/utils.dart should be tested in test/src/utils_test.dart).integration_test directory at the root of the package.Utilize package:test as the standard testing library for Dart applications.
package:test/test.dart (or package:flutter_test/flutter_test.dart for Flutter).group() function to provide shared context.test() function.expect() function alongside matchers (e.g., equals(), isTrue, throwsA()).async/await syntax. The test runner automatically waits for the Future to complete.setUp() and tearDown() callbacks.package:mockito alongside package:test to generate mock objects, configure fixed scenarios, and verify interactions.Select the appropriate test runner based on the project type and test location.
dart test command.flutter test command.dart test integration_test or flutter test integration_test.Follow this sequential workflow when implementing new test suites. Copy the checklist to track your progress.
test/ directory, ensuring the _test.dart suffix.package:test/test.dart and the target library.main() function.setUp().test() cases grouped by functionality using group().Demonstrates grouping, setup, synchronous, and asynchronous testing.
Demonstrates configuring a mock object for dependency injection testing.