패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.10

state_notifier_test

StateNotifier를 테스트하기 쉽게 만드는 테스트 라이브러리입니다. state_notifier, riverpod 또는 flutter_riverpod 패키지와 함께 사용하도록 설계되었습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2천
좋아요
22
Pub 점수
150

패키지 설치

flutter pub add state_notifier_test

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

StateNotifier 클래스 테스트를 간소화하도록 설계된 테스트 라이브러리로, state_notifier, Riverpod, flutter_riverpod와 호환됩니다. 상태 변경을 쉽게 확인하고 비동기 업데이트를 처리하며 오류 조건을 테스트할 수 있는 유틸리티를 제공합니다. 이 패키지는 Flutter 테스트 워크플로우에 원활하게 통합되어 다양한 플랫폼에서 반응형 상태 로직에 대한 신뢰성 있고 유지보수 가능한 테스트를 작성할 수 있도록 도와줍니다.

사용 사례

  • StateNotifier에서 상태 전이 테스트
  • 비동기 상태 업데이트 확인
  • 상태 로직에서 오류 처리 검증
  • Unit testing Riverpod 기반 상태 관리
  • 플랫폼 간 일관된 동작 보장

주요 기능

  • 상태 변경의 간편한 확인
  • 비동기 상태 테스트 지원
  • Riverpod 생태계와의 통합
  • 최소한의 보일러플레이트
  • 크로스 플랫폼 호환성
  • 일반적인 시나리오용 테스트 보조 메서드

적합한 대상

  • Riverpod 또는 state_notifier를 사용하는 Flutter 개발자
  • 테스트 신뢰성을 우선시하는 팀
  • 복잡한 상태 로직을 가진 프로젝트
  • 강력한 단위 테스트가 필요한 CI/CD 파이프라인
  • 깨끗하고 고립된 상태 테스트를 작성하는 개발자

고려 사항

  • state_notifier, riverpod 또는 flutter_riverpod가 필요합니다
  • StateNotifier 기반 상태 관리에 제한됨
  • 복잡한 종속성에 대해 추가 설정이 필요할 수 있습니다
  • 위젯 수준의 통합 테스트를 위한 것이 아님
  • 다른 테스트 패키지(예: mockito 또는 test)와 함께 사용하는 것이 가장 좋습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

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.

카테고리

의존성

의존성 목록 5 개

소스 저장소

이 패키지를 사용하는 프로젝트