gwt-testing
GWT Testing
Use these instructions to write clean, readable tests with Given/When/Then semantics.
Terminology Map
Use the agnostic terms below throughout this skill.
| Agnostic term | JS/TS example | Dart example |
|---|---|---|
| Suite block | describe |
group |
| Case block | it / test |
test |
| Setup once (for a suite) | before |
setUpAll |
| Setup each (per case) | beforeEach |
setUp |
| Teardown once (for a suite) | after |
tearDownAll |
| Teardown each (per case) | afterEach |
tearDown |
When this skill says:
- "suite block", read
describe(JS/TS) orgroup(Dart) - "case block", read
it/test(JS/TS) ortest(Dart) - "setup hook", read
before/beforeEach(JS/TS) orsetUpAll/setUp(Dart) - "teardown hook", read
after/afterEach(JS/TS) ortearDownAll/tearDown(Dart)
Rules
- Keep maximum nesting depth to 3 levels:
suite -> suite -> case. - Never nest
Givenblocks inside anotherGivenblock. - Put setup and action code in setup hooks for the scenario.
- Prefer assertion-only case blocks.
- If a
Whenhas only oneThen, use a single case title (When ... then ...); in this collapsed form, putting theWhenaction inside the case body is acceptable. - Remove wrapper describes that do not add scenario context.
- Write explicit scenario titles:
Given <subject> with <condition>.
Writing Workflow
- Define scenarios as top-level
Givensuite blocks. - Add setup hooks per scenario to arrange and act.
- Add case blocks for outcomes (
When ... then ...) with assertions only. - Keep nesting shallow and remove redundant wrappers.
- Run tests and formatter.
Pseudocode Pattern
suite("Given <subject> with <state>", () => {
setup_each(() => {
// arrange
// act
})
case("When <event> then <outcome>", () => {
// assert only
})
})
Anti-Patterns
- Nesting
GiveninsideGiven. - Calling the SUT inside a case block when it can be executed in setup hooks.
- Mixing setup/action/asserts in a single case block.
- Adding wrapper suite blocks with no new context.
- Depth greater than
suite -> suite -> case.
Review Checklist
- Are there any nested
Givenblocks? - Does each case block contain assertions only?
- Is setup/action moved into setup hooks of the relevant scenario?
- Are single
When+ singleThencases collapsed into one case block? - Is nesting depth <= 3?
More from exaby73/skills
pub-package-explorer
Find and read source code for Dart or Flutter packages from project dependencies or pub.dev. Use when asked to inspect package implementation details, trace dependency code, locate package files by resolving `.dart_tool/package_config.json`, or inspect a package that is not currently installed by unpacking it with `dart pub unpack`.
17git-committer
Generates conventional one line commit messages from a git diff
16gwt-tester
Write or refactor tests using clear Given/When/Then structure. Use when creating new tests, improving test readability, or standardizing test files with setup hooks, assertion-only Then blocks, and shallow suite nesting.
8temp-output-clipboard
Generate user-requested text into a temporary file and copy it to the system clipboard. Use when the user asks to draft, write, or generate text and wants quick copy/paste. Default to a Markdown temp file (`.md`) unless the user explicitly asks for another format.
2gh-pr-review-posting
Post GitHub pull request reviews through `gh api`, with emphasis on a single API call that submits `REQUEST_CHANGES` plus inline comments in one payload. Use when asked to post review findings to a PR, batch inline comments, write payload JSON to `/tmp`, replace accidentally posted standalone inline comments, or convert review/comment bodies to Markdown formatting.
2