mogen_integration_tests 1.1.0 copy "mogen_integration_tests: ^1.1.0" to clipboard
mogen_integration_tests: ^1.1.0 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:test integration test file under test/integration/features/<feature>/
  • a shared test/integration/dio_helper.dart helper if one does not already exist
  • a setUp() block that creates a fresh Dio client 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 #

The file is written to test/integration/features/auth/authenticate_auth_integration_test.dart (the file name combines the endpoint's first path segment and the remaining segments so endpoints with the same trailing name never overwrite each other).

// GENERATED BY mogen_integration_tests — DO NOT EDIT
// ignore_for_file: lines_longer_than_80_chars

import 'package:dio/dio.dart';
import 'package:test/test.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) {
        // Fail only when the server could not be reached; HTTP
        // error codes still prove the endpoint is reachable.
        if (e.type == DioExceptionType.connectionError ||
            e.type == DioExceptionType.connectionTimeout ||
            e.type == DioExceptionType.unknown) {
          fail('Connection failed: ${e.message}');
        }
      }
    });
  });
}

Notes #

  • The generator only scans GET calls in datasource methods.
  • It does not generate body payloads, query parameters, or scaffolding for POST/PUT requests.
  • test/integration/dio_helper.dart is generated automatically if missing; update it for your app's API base URL and auth flow.
  • Endpoint paths must be plain string literals; dio.get('/users/$id')-style interpolated paths are skipped (reported with --verbose).
  • Only required method/constructor parameters are filled with defaults ('', 1, 1.0, false); optional parameters are omitted.
  • Constructors are inspected, so AuthRemoteDataSource({required this.dio}) generates AuthRemoteDataSource(dio: dio).

Supported source naming #

  • *_remote_datasource.dart files under lib/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
path Cross-platform path handling
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 --root at the project you want to scan.
1
likes
0
points
245
downloads

Publisher

unverified uploader

Weekly Downloads

Scans datasource GET endpoints and auto-generates integration test scaffolding.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, args, dart_style, path, yaml

More

Packages that depend on mogen_integration_tests