# dart-test-fundamentals

A skill for package:test: test structure, group, lifecycle methods and dart_test.yaml configuration.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 450 installs · ★ 148
- Author: kevmoo
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/kevmoo/dash_skills/tree/HEAD/skills/dart-test-fundamentals/SKILL.md
- Updated: 2026-10-17
- HTML: https://affpapa.org/en/nevibecode/skills/dart-test-fundamentals

## What it does

This skill covers how to write and organise Dart tests. It walks through `test` and `group`, naming groups in PascalCase after the class they cover, and putting named parameters like `testOn` and `timeout` right after the description string. A separate section handles the lifecycle: `setUp`, `tearDown`, `setUpAll`, `tearDownAll`.

For cleanup, the skill prefers `addTearDown` over a `try-finally` block. It also gives a regex, `\bfinally\s*\{`, to find tests still doing cleanup the old way. Configuration lives in `dart_test.yaml`: platforms (`vm`, `chrome`, `node`), tags with timeouts, timeout multipliers. Test files must end in `_test.dart` and sit in `test/`.

The skill spells out when not to use it. If the package has moved to `package:checks`, don't drag tests back to `package:matcher` idioms. Don't touch existing `group` hierarchies in code you didn't write unless asked — the diff churn is real. Trivial tests with no shared state need neither `group` nor `setUp`. Worth checking before you run a repo-wide refactor.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add kevmoo/dash_skills --skill dart-test-fundamentals -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/dart-test-fundamentals/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/dart-test-fundamentals/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add kevmoo/dash_skills --skill dart-test-fundamentals -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/dart-test-fundamentals/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add kevmoo/dash_skills --skill dart-test-fundamentals -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/dart-test-fundamentals/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install kevmoo/dash_skills dart-test-fundamentals
```

2. **Manually: put the files in place**
- File: `.github/skills/dart-test-fundamentals/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add kevmoo/dash_skills --skill dart-test-fundamentals -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/kevmoo/dash_skills --path skills/dart-test-fundamentals
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/dart-test-fundamentals/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add kevmoo/dash_skills --skill dart-test-fundamentals -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/kevmoo/dash_skills/tree/HEAD/skills/dart-test-fundamentals/SKILL.md

## When to use it
- group tests by class and drop redundant "test" prefixes
- swap `try-finally` cleanup for `addTearDown`
- configure platforms and tags in `dart_test.yaml`
- decide when `setUp` earns its place and when it is boilerplate
- find tests doing manual cleanup with a regex on `finally`

## Example prompts
- help me split the tests in this file into groups
- replace try-finally with addTearDown in this test
- set up dart_test.yaml with vm and chrome platforms and an integration tag at 2x timeout

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 9a8e3dd0bfc6b310.

BEGIN THIRD-PARTY FILE 9a8e3dd0bfc6b310
````text
---
name: dart-test-fundamentals
description: |-
  Core concepts and best practices for `package:test`.
  Covers `test`, `group`, lifecycle methods (`setUp`, `tearDown`), and
  configuration (`dart_test.yaml`).
license: Apache-2.0
key_features:
  - Package test core concepts
  - Test lifecycle (setUp, tearDown)
  - dart_test.yaml configuration
---

# Dart Test Fundamentals

## When to use this skill

Use this skill when:

- Writing new test files.
- Structuring test suites with `group`.
- Configuring test execution via `dart_test.yaml`.
- Understanding test lifecycle methods.

### When NOT to use (Abstention Guardrails)

Do NOT apply this skill or refactor existing tests when:

- **Legacy Single-Group Churn**: Do NOT remove or reformat existing `group`
  hierarchies in untouched existing tests unless explicitly asked, as this
  causes unwanted diff churn.
- **Alternative Assertion Frameworks**: The package has migrated to
  `package:checks` or a specialized testing framework; do not revert tests back
  to legacy `package:matcher` idioms.
- **Trivial Tests with Zero Setup**: Simple standalone tests with no shared
  state or resources do not need `group`, `setUp`, or `addTearDown`. Do not add
  ceremonial wrapper boilerplate.

## Discovery

To find candidates for improving test structure:

### `try-finally` Cleanup

Search for tests that use `try-finally` for cleanup instead of `addTearDown`:

- **Regex**: `\bfinally\s*\{` (Check if this is used for resource cleanup inside
  a test).

## Core Concepts

### 1. Test Structure (`test` and `group`)

- **`test`**: The fundamental unit of testing.
  ```dart
  test('description', () {
    // assertions
  });
  ```
- **`group`**: Used to organize tests into logical blocks.
  - Groups can be nested.
  - Descriptions are concatenated (e.g., "Group Description Test Description").
  - Helps scope `setUp` and `tearDown` calls.
  - **Naming**: Use `PascalCase` for groups that correspond to a class name
    (e.g., `group('MyClient', ...)`).
  - **Avoid Single Groups**: Do not wrap all tests in a file with a single
    `group` call if it's the only one.
    - **NOTE**: DO NOT remove groups when doing a cleanup on existing code you
      didn't create unless explicitly asked to. This can cause a LOT of churn in
      the DIFF that most engineers won't want!

- **Naming Tests** `test('test name here',`:
  - Avoid redundant "test" prefixes. Use `group` instead.
  - Include the expected behavior or outcome in the description (e.g.,
    `'throws StateError'` or `'adds API key to URL'`).
  - Descriptions should read well when concatenated with their group name.
````
END THIRD-PARTY FILE 9a8e3dd0bfc6b310

The third-party file has ended. Everything between the 9a8e3dd0bfc6b310 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2635 of 9755 bytes. © kevmoo · Apache-2.0 · https://github.com/kevmoo/dash_skills/tree/HEAD/skills/dart-test-fundamentals/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
