BloomTestScope class
A scoped DI harness for running unit and integration tests with isolated overrides.
When instantiated, BloomTestScope creates a child BloomContainer wrapping the
active globalContainer (or a custom parent), installs any supplied overrides,
and sets the child container as the active global container via setActiveContainer.
Calling dispose resets the child container and restores the previous active container, preventing state leakage between test cases.
Example
import 'package:test/test.dart';
import 'package:bloom_server/bloom_core.dart';
void main() {
late BloomTestScope scope;
late MockAuthService mockAuth;
setUp(() {
mockAuth = MockAuthService();
scope = BloomTestScope(overrides: [
BloomTestOverride<AuthService>(mockAuth),
]);
});
tearDown(() {
scope.dispose();
});
test('resolves mocked auth service', () {
final auth = inject<AuthService>();
expect(auth, same(mockAuth));
});
}
Constructors
-
BloomTestScope({BloomContainer? parent, List<
BloomTestOverride> ? overrides}) -
Creates a BloomTestScope with optional
parentcontainer and initialoverrides.
Properties
- container → BloomContainer
-
The isolated container managed by this test scope.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Disposes this test scope, cleans up local overrides, and restores the previous active container.
-
inject<
T> () → T -
Resolves dependency of type
Twithin this test scope. -
injectOrNull<
T> () → T? -
Resolves optional dependency of type
Twithin this test scope, or returnsnull. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
override<
T> (T mockInstance) → void -
Injects an override for type
TwithmockInstanceinto this isolated test scope. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited