skills/dart-test-fundamentals/SKILL.md
Core concepts and best practices for `package:test`. Covers `test`, `group`, lifecycle methods (`setUp`, `tearDown`), and configuration (`dart_test.yaml`).
npx skillsauth add kevmoo/dash_skills dart-test-fundamentalsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
test('description', () {
// assertions
});
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.
test('description', testOn: 'vm', () {
// assertions
});
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:
test('can create and delete a file', () {
final file = File('temp.txt');
try {
file.writeAsStringSync('hello');
expect(file.readAsStringSync(), 'hello');
} finally {
if (file.existsSync()) file.deleteSync();
}
});
Prefer:
test('can create and delete a file', () {
final file = File('temp.txt');
// Register teardown immediately after resource creation intent
addTearDown(() {
if (file.existsSync()) file.deleteSync();
});
file.writeAsStringSync('hello');
expect(file.readAsStringSync(), 'hello');
});
dart_test.yaml)The dart_test.yaml file configures the test runner. Common configurations
include:
Define where tests run (vm, chrome, node).
platforms:
- vm
- chrome
Categorize tests to run specific subsets.
tags:
integration:
timeout: 2x
Usage in code:
@Tags(['integration'])
import 'package:test/test.dart';
Running tags:
dart test --tags integration
Set default timeouts for tests.
timeouts:
2x # Double the default timeout
_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).testing
Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines.
documentation
Guidelines for maintaining external Dart packages, covering versioning, publishing workflows, and pull request management. Use when updating Dart packages, preparing for a release, or managing collaborative changes in a repository.
development
Guidelines and best practices for refactoring consecutive prints, single-line string concatenations, and complex output blocks into triple-quoted multi-line string literals (''' or """) in Dart.
tools
Guidelines for using modern Dart features (v3.0 - v3.10) such as Records, Pattern Matching, Switch Expressions, Extension Types, Class Modifiers, Wildcards, Null-Aware Elements, and Dot Shorthands.