Create test
Behavioral blueprints for agents.
npx -y skills add anoopsg/agent_rules --skill create-testAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Process for creating unit and widget tests in the test/ directory mirroring the lib/src/ directory structure. Covers using Mockito.
SKILL.md
2.3 KB, as published. Nobody here has run it
Testing Skill
This skill defines the process for writing and running unit and widget tests in the project.
1. Directory Structure
Test files must mirror the lib/src/ directory hierarchy under test/:
lib/src/
└── infrastructure/
└── auth/
└── auth_repository.dart
test/src/
└── infrastructure/
└── auth/
└── auth_repository_test.dart
All test files must end with the _test.dart suffix.
2. Mocking Guidelines
- Mocking Tool: Use the
mockitopackage for mocking infrastructure and external client dependencies. - Generator: Annotate test files with
@GenerateMocksto auto-generate mocks usingbuild_runner.
2.1 Generating Mocks Example
Annotate your test file's main() method with the dependencies to mock:
import 'package:apple_project/src/infrastructure/auth/auth_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
// Import the generated mock file (ends with .mocks.dart)
import 'auth_repository_test.mocks.dart';
@GenerateMocks([AuthRepository])
void main() {
// Test code goes here
}
To build/generate the mock implementation, run:
melos run generate
3. Writing Unit Tests
Structure tests logically using group, test, and standard Mockito APIs:
void main() {
late MockAuthRepository mockAuthRepo;
setUp(() {
mockAuthRepo = MockAuthRepository();
});
group('AuthRepository Tests', () {
test('login returns success on correct credentials', () async {
// Arrange
when(mockAuthRepo.login('user', 'pass'))
.thenAnswer((_) async => const Ok(null));
// Act
final result = await mockAuthRepo.login('user', 'pass');
// Assert
expect(result.isOk, isTrue);
verify(mockAuthRepo.login('user', 'pass')).called(1);
});
});
}
4. Running Tests
- Run all unit and widget tests:
flutter test - Run tests for a specific test file:
flutter test test/src/infrastructure/auth/auth_repository_test.dart