npx skills add ...
npx skills add flutter/skills --skill dart-test-fundamentals
npx skills add flutter/skills --skill dart-test-fundamentals
Core concepts and best practices for `package:test`. Covers `test`, `group`, lifecycle methods (`setUp`, `tearDown`), and configuration (`dart_test.yaml`).
Use this skill when:
group.dart_test.yaml.To find candidates for improving test structure:
try-finally CleanupSearch for tests that use try-finally for cleanup instead of addTearDown:
\bfinally\s*\{ (Check if this is used for resource cleanup
inside a test).test and group)test: The fundamental unit of testing.
group: Used to organize tests into logical blocks.
setUp and tearDown calls.PascalCase for groups that correspond to a class name
(e.g., group('MyClient', ...)).group call if it's the only one.
Naming Tests test('test name here',:
group instead.'throws StateError' or 'adds API key to URL').Named Parameters Placement:
test and group calls, place named parameters (e.g., testOn,
timeout, skip) immediately after the description string, before the
callback closure. This improves readability by keeping the test logic last.
setUp, tearDown)setUp: Runs before every test in the current group (and nested
groups).tearDown: Runs after every test in the current group.setUpAll: Runs once before any test in the group.tearDownAll: Runs once after all tests in the group.Best Practice:
setUp for resetting state to ensure test isolation.test body, consider using
addTearDown instead of a try-finally block.Avoid:
Prefer:
dart_test.yaml)The dart_test.yaml file configures the test runner. Common configurations
include:
Define where tests run (vm, chrome, node).
Categorize tests to run specific subsets.
Usage in code:
Running tags:
dart test --tags integration
Set default timeouts for tests.
_test.dart to be picked up by the test runner.test/ directory.dart test: Run all tests.dart test test/path/to/file_test.dart: Run a specific file.dart test --name "substring": Run tests matching a description.dart-test-fundamentals is the core skill for structuring and configuring
tests. For writing assertions within those tests, refer to:
package:matcher (expect calls).package:checks (check calls).