--- description: Flutter testing guidelines covering unit, widget, and integration tests. globs: "test/**/*.dart" --- # Flutter Testing Rules ## Test Structure - Follow Arrange-Act-Assert (Given-When-Then) pattern. - Name test variables clearly: inputX, mockX, actualX, expectedX. - Mirror lib/ directory structure in test/. - One test file per source file. ## Unit Tests - Write unit tests for all domain logic and use cases. - Test repository implementations with mock data sources. - Test BLoC/Cubit state transitions thoroughly. - Use package:test for pure Dart unit tests. ## Widget Tests - Use package:flutter_test for widget tests. - Test rendering, interaction, and state changes. - Use pumpWidget() and pump() for async rendering. - Use find.byType, find.byKey, find.text for assertions. - Verify widget rebuilds correctly with different states. ## Integration Tests - Use package:integration_test for end-to-end flows. - Test critical user journeys (login, navigation, data flow). - Add integration_test as dev_dependency with sdk: flutter. ## Mocking - Prefer fakes and stubs over mocks. - Use mockito or mocktail when mocks are necessary. - Avoid code generation for mocks when possible. - Mock external services (APIs, databases) at repository boundary. ## Best Practices - Aim for high test coverage on domain and data layers. - Test error states and edge cases. - Keep tests fast and independent. - Use setUp() and tearDown() for common setup. - Run tests in CI/CD pipeline.