No slash command · from dart-foundation
Tests pure Dart code with package:test: file layout, group/test/setUp structure, matchers, async/stream expectations, mocktail mocks, and coverage collection. Stack-agnostic, referenced by all Dart plugins.
Ships in dart-foundation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
test/, mirroring lib/: lib/src/cart/cart.dart → test/src/cart/cart_test.dart._test.dart and has a main().test/helpers/ (or the repo's existing location) — not in lib/.dart test. Flutter projects run the same tests with flutter test (which uses flutter_test; its test/expect API is the same).import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
class _MockOrderRepository extends Mock implements OrderRepository {}
void main() {
group(CheckoutService, () {
late _MockOrderRepository repository;
late CheckoutService service;
setUp(() {
repository = _MockOrderRepository();
service = CheckoutService(repository);
});
test('places an order when the cart is not empty', () async {
// Arrange
when(() => repository.save(any())).thenAnswer((_) async {});
final cart = Cart(items: [CartItem(sku: 'A1', quantity: 2)]);
// Act
final order = await service.checkout(cart);
// Assert
expect(order.items, hasLength(1));
verify(() => repository.save(order)).called(1);
});
test('throws EmptyCartException for an empty cart', () {
expect(() => service.checkout(Cart.empty()), throwsA(isA<EmptyCartException>()));
verifyNever(() => repository.save(any()));
});
});
}
group by unit (pass the type itself: group(CheckoutService, ...)), test names as behaviour sentences.setUp creates fresh state for every test; tearDown / addTearDown releases resources (close controllers, delete temp dirs). Never share mutable state across tests via top-level variables.The default is mocktail (no code generation). If the project already uses mockito with @GenerateNiceMocks + build_runner, stay with it — do not mix both.
registerFallbackValue(FakeOrder()) in setUpAll before using any() with a non-primitive type.when(...) calls.thenAnswer((_) async => value), never thenReturn(Future.value(...)).package:http/testing.dart MockClient((request) async => Response('{"id":1}', 200)) beats mocking http.Client methods by hand.expect(total, equals(Money.cents(1999)));
expect(items, containsAll([a, b]));
expect(user, isA<AdminUser>().having((u) => u.permissions, 'permissions', contains(Permission.billing)));
expect(() => parse('x'), throwsA(isA<FormatException>()));
expect(price, closeTo(9.99, 0.001));
isA<T>().having(...) beats several separate expects on casted fields.
test('emits loading then data', () {
expect(
repository.watchOrders(),
emitsInOrder([isEmpty, hasLength(1), emitsDone]),
);
});
test('surfaces errors', () async {
await expectLater(service.load(), throwsA(isA<NetworkException>()));
});
await (or return) async expectations — expectLater for futures, the stream matcher form for streams. An un-awaited expectation passes vacuously.Clock (package:clock) or a DateTime Function() — never call DateTime.now() deep inside logic.fakeAsync((async) { ...; async.elapse(const Duration(seconds: 5)); }) from package:fake_async — no real Future.delayed in tests.@Tags(['integration']) at the top of the file, declared in dart_test.yaml; CI may run dart test -x integration.@TestOn('vm') / @TestOn('browser') when a test depends on dart:io or dart:html.dart test --coverage=coverage
dart pub global run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
# Flutter: flutter test --coverage → coverage/lcov.info
Exclude generated files (*.g.dart, *.freezed.dart) from coverage targets. Cover branches and error paths of new code, not trivial getters.
sleep/Future.delayed to "wait for" async work.toString() output instead of structured fields.What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/dart-conventionsModern Dart idioms for any Dart project (Dart 3+): sound null safety, records, patterns and switch expressions, sealed/final/base/interface class modifiers, extension types, Future/Stream discipline, immutability, Effective Dart naming, library layout. Apply when the project is a Dart 3 project (pure Dart or Flutter). Stack-agnostic — referenced by every Dart plugin in the marketplace.
Use this skill to:
- Write null-safe code without `!` sprinkled over every access.
- Model closed type hierarchies with sealed classes and exhaustive switch expressions.
- Return multiple values with records instead of ad-hoc wrapper classes.
- Write correct async code (no unawaited futures, no leaked stream subscriptions).
- Lay out a package the way the Dart tooling expects (lib/, lib/src/, bin/, test/).
Do NOT use this skill for:
- Flutter widgets, state management or navigation — see flutter-plugin skills.
- pubspec, lints and code generation — see dart-foundation:dart-tooling.
- Testing patterns — see dart-foundation:dart-testing.
/dart-toolingDart and Flutter project tooling: pubspec.yaml dependency constraints, dart pub / flutter pub workflow, pubspec.lock policy, pub workspaces and melos monorepos, analysis_options.yaml with lint packages (lints, flutter_lints, very_good_analysis), dart format / dart analyze / dart fix, build_runner code generation (freezed, json_serializable, riverpod_generator, mockito). Stack-agnostic — referenced by every Dart plugin in the marketplace.
Use this skill to:
- Add a dependency with the right constraint in the right section.
- Run the project's own formatter, analyzer and generator the way CI does.
- Decide whether to commit pubspec.lock and generated files.
- Work inside a pub workspace or melos monorepo without breaking sibling packages.
Do NOT use this skill for:
- Language idioms — see dart-foundation:dart-conventions.
- Testing patterns — see dart-foundation:dart-testing.
npx claudepluginhub aratkruglik/claude-sdlc --plugin dart-foundationOther plugins' skills for the same job