test-best-practices

When to use this skill

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "test-best-practices" with this command: npx skills add kevmoo/dash_skills/kevmoo-dash-skills-test-best-practices

When to use this skill

In a Dart or Flutter project. When a user asks to "enforce test best practices" or similar. When modifying or creating test files.

Workflow

  • Search: Use the grep commands below to identify candidates.

  • Analyze: Check if the code violates the best practices defined below.

  • Apply: Refactor the code to use the recommended matchers.

  • Verify: Run tests (dart test ) to ensure no regressions.

Search Strategies

  • .length : grep -r ".length,\s*equals(" test/

  • Boolean properties: grep -rE "expect(..(is(Empty|NotEmpty)),\s(isTrue|true|isFalse|false)" test/

  • Manual loops: grep -r "for (var .* in .*)" test/ (manual review required)

Best Practice Patterns

Collections

Use hasLength

Prefer expect(list, hasLength(n)) over expect(list.length, n) . Applies to: Iterable , Map , String .

Use isEmpty / isNotEmpty

Prefer expect(list, isEmpty) over expect(list.isEmpty, true) . Prefer expect(list, isNotEmpty) over expect(list.isNotEmpty, true) or expect(list, isNot(isEmpty)) . Applies to: Iterable , Map , String .

Declarative Verification

Prefer expect(list, everyElement(matcher)) over manual loops with assertions.

List Equality

Prefer expect(actualList, expectedList) over manual loops checking elements by index. package:test provides readable diffs for list mismatches.

Maps

Use containsPair

Prefer expect(map, containsPair(key, value)) over expect(map[key], value) .

Note: If verifying a key is missing, use expect(map, isNot(contains(key))) .

Strict Equality

Prefer expect(map, {'k': 'v'}) over multiple containsPair calls when the full map is known.

Types & Objects

Declarative Type Checks

Prefer expect(obj, isA<T>()) over expect(obj is T, isTrue) .

Grouped Assertions

Prefer chaining having on isA<T> for multiple property checks.

expect(obj, isA<MyType>() .having((o) => o.prop1, 'prop1', a) .having((o) => o.prop2, 'prop2', b));

Constraints

  • Verify Types: Ensure subject is strictly Iterable /Map before applying collection matchers. Some custom classes (e.g. PriorityQueue ) may have .length but don't implement Iterable .

  • Do NOT migrate to package:checks: Unless explicitly requested. This skill focuses on package:test matchers.

  • Preserve Behavior: Ensure refactorings do not change strictness.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

dart-best-practices

No summary provided by upstream source.

Repository SourceNeeds Review
143-kevmoo
General

dart-test-fundamentals

No summary provided by upstream source.

Repository SourceNeeds Review
118-kevmoo
General

dart-package-maintenance

No summary provided by upstream source.

Repository SourceNeeds Review
General

dart-modern-features

No summary provided by upstream source.

Repository SourceNeeds Review