パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.0.10

state_notifier_test

StateNotifierのテストを簡単にできるテストライブラリです。state_notifier、riverpod、またはflutter_riverpodパッケージと併用するように設計されています。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1970
いいね数
22
Pub ポイント
150

パッケージをインストール

flutter pub add state_notifier_test

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

StateNotifier クラスのテストを簡素化するためのテストライブラリで、state_notifier、Riverpod、flutter_riverpod と互換性があります。状態変更の容易なアサーション、非同期更新の処理、エラー状態のテストに役立つユーティリティを提供します。このパッケージは Flutter テストワークフローにシームレスに統合され、複数のプラットフォームで反応型の状態ロジックに対する信頼性が高く保守しやすいテストの作成を可能にします。

用途

  • StateNotifierにおける状態遷移のテスト
  • 非同期状態の更新を確認する
  • 状態ロジックにおけるエラー処理の検証
  • ユニットテストによる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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト