FakeInjector class

Implementação falsa de InjectorReader para testes unitários.

Permite resolver dependências sem o container global de binds, tornando testes de serviços, use cases e módulos rápidos e isolados.

Uso:

final injector = FakeInjector.empty()
    .add<PaymentGateway>(FakePaymentGateway())
    .add<UserRepository>(FakeUserRepository());

final service = OrderService(
  injector.get<PaymentGateway>(),
  injector.get<UserRepository>(),
);

Object Calisthenics:

  • Uma única variável de instância (Regra 8)
  • Imutável — add retorna novo injector (sem setters — Regra 9)
  • Falha com erro descritivo em vez de retornar null (sem primitivos nus)
Implemented types

Constructors

FakeInjector.empty()

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

add<T>(T instance) FakeInjector
Retorna um novo FakeInjector com instance registrada para o tipo T.
get<T>({String? key}) → T
Resolve a instância do tipo T.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited