ModularTestScope class
Facade principal da testing API.
Centraliza o ciclo de vida de DI e eventos em testes, garantindo isolamento entre cada execução sem boilerplate manual.
Padrão com template (binds compartilhados entre todos os testes):
final scope = ModularTestScope.fresh()
.withInstance<AppConfig>(AppConfig.test())
.withLazySingleton<ApiClient>(() => ApiClient());
setUp(scope.setUp);
tearDown(scope.tearDown);
test('...', () {
scope.registerInstance<MyService>(FakeMyService()); // per-test override
expect(scope.get<MyService>(), isA<FakeMyService>());
});
Padrão simples (tudo configurado no setUp):
final scope = ModularTestScope.fresh();
setUp(() {
scope.setUp();
scope.registerInstance<MyService>(FakeMyService());
scope.listenFor<MyEvent>();
});
tearDown(scope.tearDown);
Object Calisthenics:
- Duas variáveis de instância (Regra 8)
- Métodos
withXxxretornam novo scope (imutável por template — Regra 9) - Registros diretos via
registerXxxsão operações explícitas (sem magia)
Constructors
- ModularTestScope.fresh()
-
Cria um scope limpo, sem nenhum bind ou listener pré-configurado.
factory
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
-
clearRecordedEvents(
) → void - Apaga os eventos gravados sem cancelar os listeners.
-
eventsOf<
E> () → RecordedEventList< E> -
Retorna os eventos gravados do tipo
E. -
fireEvent<
E> (E event, {EventBus? eventBus}) → void - Dispara um evento no EventBus global.
-
get<
T> ({String? key}) → T -
Resolve o tipo
Tdo container global. -
isRegistered<
T> ({String? key}) → bool -
Retorna
truese o tipoTestá registrado no container global. -
listenFor<
E> ({EventBus? eventBus}) → void -
Inicia a gravação de eventos do tipo
E. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerFactory<
T> (T factory()) → void - Registra uma factory imediatamente no container global.
-
registerInstance<
T> (T instance) → void - Registra um singleton imediatamente no container global.
-
registerLazySingleton<
T> (T factory()) → void - Registra um lazy singleton imediatamente no container global.
-
setUp(
) → void - Limpa todo o estado global e aplica o template de binds.
-
tearDown(
) → void - Cancela listeners de eventos, limpa o container de DI e o estado de eventos.
-
toString(
) → String -
A string representation of this object.
inherited
-
withFactory<
T> (T factory()) → ModularTestScope - Adiciona uma factory ao template — reaplicada a cada setUp.
-
withInstance<
T> (T instance) → ModularTestScope - Adiciona um singleton ao template — reaplicado a cada setUp.
-
withLazySingleton<
T> (T factory()) → ModularTestScope - Adiciona um lazy singleton ao template — reaplicado a cada setUp.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited