mocktail
FeaturedUse when creating mocks, stubbing methods, verifying interactions, registering fallback values, or choosing between mocks, fakes, and real objects (Mocktail).
AI & Automation 619 stars
60 forks Updated today MIT
Install
Quality Score: 95/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# Mocktail Skill
This skill defines how to correctly use the `mocktail` package for mocking in Dart and Flutter tests.
---
## 1. Mock vs. Fake vs. Real Object
| Use | When |
|---|---|
| **Real object** | Prefer over mocks when practical. |
| **Fake** (`extends Fake`) | Lightweight custom implementation; override only the methods you need. Prefer over mocks when you don't need interaction verification. |
| **Mock** (`extends Mock`) | Only when you need to **verify interactions** (call counts, arguments) or stub dynamic responses. |
- Never add `@override` methods or implementations to a class extending `Mock`.
- Only use mocks if your test has `verify` assertions; otherwise prefer real or fake objects.
---
## 2. Creating Mocks
```dart
class MockMyService extends Mock implements MyService {}
class FakeMyEvent extends Fake implements MyEvent {}
```
No code generation required — unlike Mockito, Mocktail uses `noSuchMethod` at runtime.
---
## 3. Registering Fallback Values
Register fallback values **before** using custom types with argument matchers. Do this in `setUpAll` or at the top of your test:
```dart
setUpAll(() {
registerFallbackValue(FakeMyEvent());
});
```
- Required for non-nullable custom types used with `any()`, `captureAny()`, or `captureThat()`.
- Register fallback values for **any** custom type used with argument matchers.
---
## 4. Stubbing
```dart
final mock = MockMyService();
// Return a value
when(() => mock.fetchData()).thenReturn('result')...
Details
- Author
- evanca
- Repository
- evanca/flutter-ai-rules
- Created
- 1 years ago
- Last Updated
- today
- Language
- Shell
- License
- MIT
Similar Skills
Semantically similar based on skill content — not just same category
Testing & QA Featured
mockito
Use when generating mocks, stubbing methods, verifying interactions, capturing arguments, or choosing between mocks, fakes, and real objects (Mockito).
619 Updated today
evanca Testing & QA Listed
flutter-test-unit
Unit testing using test + mockito
0 Updated 6 days ago
noory-code Testing & QA Listed
api-testing-observability-api-mock
You are an API mocking expert specializing in realistic mock services for development, testing, and demos. Design mocks that simulate real API behavior and enable parallel development.
6 Updated 1 weeks ago
rootcastleco