mogen_integration_tests 1.0.10
mogen_integration_tests: ^1.0.10 copied to clipboard
Scans datasource GET endpoints and auto-generates integration test scaffolding.
mogen_integration_tests #
mogen_integration_tests scans lib/features/<feature>/data/datasources/*_remote_datasource.dart datasource classes and generates integration test scaffolding for discovered GET endpoints.
Generated files are written under test/integration/features/<feature>/ and include a shared test/integration/dio_helper.dart helper.
What it generates #
For each discovered GET request inside a datasource method, the generator creates:
- a
package:testintegration test file undertest/integration/features/<feature>/ - a shared
test/integration/dio_helper.darthelper if one does not already exist - a
setUp()block that creates a freshDioclient and datasource instance - a single test that calls the datasource method directly
- connectivity-aware failure handling for
DioException
Expected project layout #
The CLI scans datasource files at this path pattern:
lib/
└── features/
└── auth/
└── data/
└── datasources/
└── auth_remote_datasource.dart
Data source file names should end with
_remote_datasource.dart.
Installation #
Add this package to your Flutter app's dev_dependencies:
dev_dependencies:
mogen_integration_tests:
Then install dependencies:
dart pub get
Usage #
From the root of your Flutter app, run:
dart run mogen_integration_tests
CLI options #
| Flag | Short | Default | Description |
|---|---|---|---|
--root |
-r |
. |
Project root directory |
--dry-run |
-d |
false |
Preview generated files without writing them |
--verbose |
-v |
false |
Print detailed progress while scanning and generating |
--feature |
-f |
Only generate tests for the given feature name | |
--version |
false |
Print version and exit | |
--help |
-h |
Show the CLI help text |
Examples #
# Generate tests from the current project
dart run mogen_integration_tests
# Preview output without writing files
dart run mogen_integration_tests --dry-run --verbose
# Generate tests for a single feature
dart run mogen_integration_tests --feature auth
# Scan a different package root
dart run mogen_integration_tests --root /path/to/my_flutter_app
Example datasource #
import 'package:dio/dio.dart';
class AuthRemoteDataSource {
final Dio dio;
AuthRemoteDataSource(this.dio);
Future<void> login({required String email, required String password}) async {
await dio.get('/Authenticate/Auth');
}
}
Generated test output #
// GENERATED BY mogen_integration_tests — DO NOT EDIT
// ignore_for_file: lines_longer_than_80_chars
import 'package:dio/dio.dart';
import '../../dio_helper.dart';
import 'package:your_app/features/auth/data/datasources/auth_remote_datasource.dart';
void main() {
group('GET /Authenticate/Auth', () {
late Dio dio;
late AuthRemoteDataSource datasource;
setUp(() {
dio = buildTestDio();
datasource = AuthRemoteDataSource(dio);
});
test('calls login() successfully', () async {
try {
await datasource.login(email: '', password: '');
} on DioException catch (e) {
// A DioException means the request reached the server.
// Fail only on connectivity errors, not HTTP error codes.
if (e.type == DioExceptionType.connectionError ||
e.type == DioExceptionType.unknown) {
fail('Connection failed: ${e.message}');
}
}
});
});
}
Notes #
- The generator only scans
GETcalls in datasource methods. - It does not generate body payloads, query parameters, or scaffolding for POST/PUT requests.
test/integration/dio_helper.dartis generated automatically if missing; update it for your app's API base URL and auth flow.
Supported source naming #
*_remote_datasource.dartfiles underlib/features/**/data/datasources/- Example:
auth_remote_datasource.dart,profile_remote_datasource.dart
Dependencies #
| Package | Purpose |
|---|---|
analyzer |
Parse Dart AST for datasource analysis |
dart_style |
Format generated Dart output |
args |
CLI flag parsing |
dio |
Detect GET requests in datasource code |
yaml |
Read pubspec.yaml for package info |
Project notes #
- This repository is a CLI package, not a Flutter app.
- Generated files are written to
test/integration/features/. - When using this package as a dependency, point
--rootat the project you want to scan.