This document explains how to test the mayr_events package.
- Flutter SDK installed and configured
- Dart SDK (comes with Flutter)
To run the complete Flutter test suite:
flutter testTo run tests with coverage report:
flutter test --coveragedart format --set-exit-if-changed .dart analyze --fatal-warnings .Use the provided test script:
./test.shThe test suite (test/mayr_flutter_events_test.dart) includes:
-
Unit tests for each component:
- MayrEvent
- MayrListener
- MayrEvents (event bus)
- MayrEventSetup
-
Integration tests for complete workflows
-
Edge case tests:
- Once-only listeners
- Error handling
- Multiple listeners
- Hooks (beforeHandle, onError)
For quick verification without Flutter, a simple standalone test is available:
dart test/simple_test.dartNote: This requires the package dependencies to be resolved, which requires Flutter.
When adding new features, follow these guidelines:
- Create test events and listeners specific to your test case
- Reset the event bus before each test using
MayrEvents.instance.clear() - Test both success and failure cases
- Use descriptive test names
- Check edge cases
group('Feature Name', () {
setUp(() {
MayrEvents.instance.clear();
});
test('should do something specific', () async {
// Arrange
final listener = TestListener();
MayrEvents.instance.listen<TestEvent>(listener);
// Act
await MayrEvents.instance.fire(const TestEvent('data'));
// Assert
expect(listener.messages, ['data']);
});
});The package uses GitHub Actions for CI. See .github/workflows/ci.yaml for the complete CI configuration.
The CI pipeline runs:
- Flutter pub get
- Flutter test
- Dart format check
- Dart analyze
We aim for high test coverage (>90%) to ensure reliability. After running tests with coverage:
# Generate HTML coverage report
genhtml coverage/lcov.info -o coverage/html
# Open in browser
open coverage/html/index.htmlIf you see "Failed to resolve package" errors:
flutter clean
flutter pub getEnsure Flutter is properly installed:
flutter doctor- Check that you've cleared the event bus before each test
- Verify async/await usage is correct
- Ensure test events and listeners are properly isolated
- Check for timing issues in async tests
You can also test the package manually using the example app:
cd example
flutter pub get
flutter runInteract with the UI and observe console output to verify behavior.