agentleFS
ZAidBinAsifZAidBinAsif/flutter-ai-starter/.cursor/rules/testing.mdc

flutter-ai-starter / rules

Cursor rule0 starsChanged 5 months agoMITView on GitHub

Testing requirements — unit, widget, provider, golden, integration

The file

We split this testing.mdc into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All code units below require tests: No skipping. Use implement-tdd for red-green-refactor workflow.

    line 9
  2. Distinctive:

    Prefer fakes over mocks for code you own (repositories injected into ViewModels).

    line 32
  3. Very specific:

    Use Mockito (generate-mocks skill) for external I/O boundaries only.

    line 33
  4. Distinctive:

    Never mock internal collaborators to test implementation details.

    line 34
  5. Very specific:

    Use the implement-tdd skill for red-green-refactor workflow.

    line 67

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
testing.mdc
---
description: Testing requirements — unit, widget, provider, golden, integration
globs: ["test/**/*.dart", "lib/**/*.dart", "supabase/**/*"]
alwaysApply: false
---

# Testing requirements

**All code units below require tests.** No skipping. Use `implement-tdd` for red-green-refactor workflow.

## What must be tested

| Code unit | Test type | Tool |
|---|---|---|
| Pure function / mapper / util | Unit | `package:test` |
| Repository | Unit with fake client | `package:test` |
| ViewModel (`ChangeNotifier`) | Unit test (fake repos) | `package:test` |
| Design-system widget | Widget + golden (light + dark) | `flutter_test` |
| Screen | Widget (happy + one error path) | `flutter_test` |
| Critical flow | Integration | `integration_test` |
| Supabase table | RLS | pgTAP (when using Supabase) |

## Testing strategy (fake vs mock)

| Layer | Approach | Why |
|---|---|---|
| ViewModel unit tests | **Fake repositories** (hand-written stubs) | Test behavior through public ViewModel API |
| Repository unit tests | **Mockito** for dio / Supabase client at the boundary | Verify HTTP/query calls without real network |
| ViewModel `notifyListeners` | Optional **listener** on the ViewModel | Assert UI refresh signal only — not business logic |
| Internal private methods | **Do not test directly** | Test via public methods; refactor if untestable |

- Prefer fakes over mocks for code you own (repositories injected into ViewModels).
- Use Mockito (`generate-mocks` skill) for external I/O boundaries only.
- Never mock internal collaborators to test implementation details.

## Layout

Mirror source tree under `test/`:

```
test/
  core/...
  design_system/components/...
  features/<feature>/...
  integration/
```

## Naming

- Files: `<unit>_test.dart`
- Cases: `<unit> <does what> when <state>`

## CI expectations

- `dart format --set-exit-if-changed .`
- `flutter analyze --fatal-infos`
- `flutter test`
- `dart run build_runner build` must produce no diff when codegen is used

## Forbidden

- `skip: true` without documented reason
- Shipping new/changed code without the tests required by the table above
- Tests hitting prod Supabase or real AI vendor APIs
- Asserting behavior through private implementation details

Use the `implement-tdd` skill for red-green-refactor workflow.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.