MockRuntimeScanner class
A lightweight mock implementation of RuntimeScanner for testing and development.
This scanner provides a simplified reflection system that:
- Operates only on the current isolate's libraries
- Supports force-loading specific files
- Uses Dart's mirrors API instead of filesystem scanning
- Provides configurable logging
- Allows custom library generator injection
{@template mock_runtime_scan_features}
Key Features
- Isolated Scanning: Only processes currently loaded libraries by default
- Selective Loading: Can force-load specific files via
forceLoadFiles
- Pluggable Logging: Configurable info/warning/error callbacks
- Custom Generators: Supports alternative library generators via factory
- Primitive Type Support: Automatically includes Dart core types
When to Use
- Unit testing reflection-dependent code
- Development environments where full scanning is unnecessary
- CI pipelines requiring lightweight reflection
- Debugging specific library reflection
Basic Usage
final mockScan = MockRuntimeScan(
onInfo: (msg) => debugPrint(msg),
onError: (err) => debugPrint('ERROR: $err'),
forceLoadFiles: [
File('lib/src/critical.dart'),
File('lib/models/user.dart'),
],
);
final summary = await mockScan.scan(
'output',
RuntimeScanLoader(
scanClasses: [User, CriticalService],
),
);
{@endtemplate}
- Implemented types
Constructors
-
MockRuntimeScanner({OnLogged? onInfo, OnLogged? onWarning, OnLogged? onError, List<
File> forceLoadFiles = const [], MockLibraryGeneratorFactory? libraryGeneratorFactory, bool includeCurrentIsolateLibraries = true}) - A lightweight mock implementation of RuntimeScanner for testing and development.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
scan(
String outputFolder, RuntimeScannerConfiguration configuration, {Directory? source}) → Future< RuntimeScannerSummary> -
Executes a mock reflection scan with the given configuration.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited