Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.0.10

state_notifier_test

Uma biblioteca de testes que facilita o teste de StateNotifier. Criada para ser usada com os pacotes state_notifier, riverpod ou flutter_riverpod.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
2 mil
Curtidas
22
Pontos Pub
150

Instalar pacote

flutter pub add state_notifier_test

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Uma biblioteca de testes projetada para simplificar o teste de classes StateNotifier, compatível com state_notifier, Riverpod e flutter_riverpod. Oferece utilitários para afirmar facilmente mudanças de estado, lidar com atualizações assíncronas e testar condições de erro. O pacote se integra perfeitamente aos fluxos de teste do Flutter, permitindo que desenvolvedores escrevam testes confiáveis e sustentáveis para lógica de estado reativa em múltiplas plataformas.

Casos de uso

  • Testando transições de estado no StateNotifier
  • Verificando atualizações de estado assíncronas
  • Validando o tratamento de erros na lógica de estado
  • Testes unitários de gerenciamento de estado baseado em Riverpod
  • Garantir um comportamento consistente entre plataformas

Principais recursos

  • Afirmação fácil de mudanças de estado
  • Suporte para teste de estado assíncrono
  • Integração com o ecossistema Riverpod
  • Boilerplate mínimo
  • Compatibilidade multiplataforma
  • Métodos auxiliares de teste para cenários comuns

Indicado para

  • Desenvolvedores Flutter usando Riverpod ou state_notifier
  • Equipes que priorizam a confiabilidade de testes
  • Projetos com lógica de estado complexa
  • pipelines de CI/CD que exigem testes unitários robustos
  • Desenvolvedores escrevendo testes de estado limpos e isolados

Considerações

  • Requer estado_notifier, riverpod ou flutter_riverpod
  • Limitado ao gerenciamento de estado baseado em StateNotifier
  • Pode ser necessário configuração adicional para dependências complexas
  • Não destinado a testes de integração em nível de widget
  • Melhor usado em conjunto com outros pacotes de teste, como mockito ou test

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

Package

Package is a port of felangel's bloc_test, modified to work with StateNotifier class

Installation

Add to dev dependencies inside pubspec_yaml:

dev_dependencies:
  state_notifier_test: [version]

Usage

import 'package:state_notifier_test.dart';

stateNotifierTest(
  'CounterNotifier emits [9,10] when seeded with 9',
  build: () => CounterNotifier(),
  seed: () => [9],
  actions: (stateNotifier) => stateNotifier.increment(),
  expect: () => [9,10],
);

class CounterStateNotifier extends StateNotifier<int> {
  CounterStateNotifier() : super(0);

  void increment() {
    state = state + 1;
  }
}

stateNotifierTest can also be used to skip any number of emitted states before asserting against the expected states. skip defaults to 0.

stateNotifierTest(
  'CounterNotifier emits [2] when increment is called twice',
  build: () => CounterNotifier(),
  actions: (stateNotifier) {
    stateNotifier
      ..increment()
      ..increment();
  },
  skip: 1,
  expect: () => [2],
);

stateNotifierTest can also be used to verify internal stateNotifier functionality.

stateNotifierTest(
  'CounterNotifier emits [1] when increment is called',
  build: () => CounterNotifier(),
  actions: (stateNotifier) => stateNotifier.increment(),
  expect: () => [1],
  verify: (_) {
    verify(() => repository.someMethod(any())).called(1);
  }
);

Testing Options

setUp is optional and should be used to set up any dependencies prior to initializing the stateNotifier under test. setUp should be used to set up state necessary for a particular test case. For common set up code, prefer to use setUp from package:test/test.dart.

build should construct and return the stateNotifier under test.

seed is an optional Function that returns an Iterable of States which will be used to seed the stateNotifier before actions is called.

actions is an optional callback which will be invoked with the stateNotifier under test and should be used to interactions with the stateNotifier.

skip is an optional int which can be used to skip any number of states. skip defaults to 0.

expect is an optional Function that returns a Matcher which the stateNotifier under test is expected to emit after actions is executed.

verify is an optional callback which is invoked after expect and can be used for additional verification/assertions. verify is called with the stateNotifier returned by build.

errors is an optional Function that returns a Matcher which the stateNotifier under test is expected to throw after actions is executed.

tearDown is optional and can be used to execute any code after the test has run. tearDown should be used to clean up after a particular test case. For common tear down code, prefer to use tearDown from package:test/test.dart.

expectInitialState is an optional bool.If set to true, the initial state from the constructor will also be checked. Useful when you want to validate the initial state. Note: if set to true, it will only catch the last assigned state in the constructor. expectInitialState defaults to false.

Categorias

Dependências

Lista de dependências 5 itens

Repositório-fonte

Projetos que usam este pacote