Provider: Mock ChangeNotifier, dùng ProviderContainer để test.
- Riverpod: Dùng
ProviderContainer, override provider bằng mock. - BLoC: Test trực tiếp với
bloc_test, xác minh event → state transition. - Không bao giờ phụ thuộc
BuildContexttrong code cần test; tách logic nghiệp vụ vào service class. - State management tốt thì test dễ; nếu test khó thì kiến trúc cần xem lại.
For Provider: mock ChangeNotifiers, use ProviderContainer for testing.
- For Riverpod: override providers with mocks.
- For BLoC: use
bloc_test, verify event-to-state transitions. - Never depend on
BuildContextin testable code; if testing is hard, your architecture needs rework.