पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.1.9

riverpod_test

एक परीक्षण पुस्तकालय जो प्रदाताओं के परीक्षण को आसान बनाता है। riverpod पैकेज के साथ उपयोग करने के लिए बनाया गया है।

AndroidiOSWebmacOSWindowsLinux
30-दिन डाउनलोड
4.6 हज़ार
लाइक
28
Pub अंक
150

पैकेज इंस्टॉल करें

flutter pub add riverpod_test

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

riverpod_test एक परीक्षण पुस्तकालय है जिसका उद्देश्य फ्लटर एप्लिकेशन में Riverpod प्रदाताओं के परीक्षण को सरल बनाना है। यह आइसोलेटेड रूप से प्रदाता मानों को ओवरराइड, मॉक और परीक्षण करने के लिए उपकरण प्रदान करता है, जिससे विश्वसनीय और बनाए रखने योग्य परीक्षण सुनिश्चित होते हैं। Riverpod पैकेज के लिए विशेष रूप से बनाया गया, यह फ्लटर के परीक्षण प्रणाली के साथ बिना किसी बाधा के एकीकृत होता है, जिससे विकासकर्ताओं को वास्तविक निर्भरताओं पर निर्भर न करते हुए राज्य तर्क की जाँच करने की अनुमति मिलती है। यह पुस्तकालय सभी प्रमुख प्लेटफॉर्म को समर्थन करता है, जिससे यह क्रॉस-प्लेटफॉर्म परीक्षण कार्यप्रवाह के लिए आदर्श है।

उपयोग

  • प्रदाता अवस्था परिवर्तनों का परीक्षण
  • परीक्षणों में निर्भरताओं का मॉकिंग
  • प्रदाताओं में व्यवसाय नियमों की पुष्टि करना
  • वास्तविक डेटा स्रोत से इकाई परीक्षण को अलग करना
  • प्रदाता में एसिंक संचालन की जाँच करें

मुख्य विशेषताएँ

  • आसान प्रदाता ओवरराइड्स
  • एम्बेडेड मॉकिंग सपोर्ट
  • Flutter के टेस्ट फ्रेमवर्क के साथ एकीकरण
  • असिंक और सिंक प्रदाताओं का समर्थन
  • स्पष्ट, पठनीय परीक्षण सिंटैक्स

इनके लिए उपयुक्त

  • Riverpod का उपयोग करने वाले Flutter विकासकर्ता
  • परीक्षण विश्वसनीयता पर ध्यान केंद्रित टीमें
  • विस्तृत प्रोवाइडर परीक्षण की आवश्यकता वाले परियोजनाएँ
  • एकाधिक और एकीकृत परीक्षण लिखने वाले विकासकर्मी
  • क्रॉस-प्लेटफ़ॉर्म फ्लटर एप्लिकेशन्स

विचार योग्य बातें

  • Riverpod पैकेज की आवश्यकता है
  • Riverpod-विशिष्ट परीक्षण तक सीमित
  • जटिल परिदृश्यों के लिए अतिरिक्त सेटअप की आवश्यकता हो सकती है
  • केवल विजेट स्तर के परीक्षण के लिए उपयुक्त नहीं
  • बाहरी परीक्षण वातावरण कॉन्फ़िगरेशन पर निर्भर है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

Pub Star on Github Flutter Website License: MIT Bloc Library


Package

Package is a port of felangel's bloc_test, modified to work with Riverpod Providers.
Increase code coverage by testing all riverpod providers.

Installation

For a Flutter project:

flutter pub add --dev riverpod_test

For a Dart project:

dart pub add --dev riverpod_test

Usage

testProvider

import 'package:riverpod_test.dart';

testProvider(
  'expect [0]',
  provider: counterProvider,
  expect: () => [0],
);

final counterProvider = Provider<int>((ref) => 0);

testNotifier

testNotifier(
  'expect [2] when increment is called twice and skip: 1',
  provider: counterNotifierProvider,
  act: (notifier) => notifier
      ..increment()
      ..increment(),
  skip: 1,
  expect: () => [2],
);

final counterNotifierProvider =
    NotifierProvider<CounterNotifier, int>(CounterNotifier.new);

class CounterNotifier extends Notifier<int> {
  @override
  int build() => 0;

  void increment() => state++;
}

testAsyncNotifier (also handles StreamNotifier)

testAsyncNotifier<CounterAsyncNotifier, int>(
  'expect [AsyncData(1)] when call increment',
  provider: counterAsyncNotifierProvider(0),
  act: (notifier) => notifier.increment(),
  expect: () => <AsyncValue<int>>[const AsyncData(1)],
);

testAsyncNotifier(
  'verify if mockRepository sideEffect is called',
  provider: sideEffectAsyncNotifierProvider(1),
  overrides: [repositoryProvider.overrideWithValue(mockRepository)],
  act: (notifier) => notifier.increment(),
  verify: (_) => verify(mockRepository.sideEffect).called(1),
);

final counterAsyncNotifierProvider =
    AsyncNotifierProviderFamily<CounterAsyncNotifier, int, int>(
  CounterAsyncNotifier.new,
);

class CounterAsyncNotifier extends FamilyAsyncNotifier<int, int> {
  @override
  FutureOr<int> build(int initialValue) => initialValue;

  void increment() => state = AsyncData(value + 1);
}

class MockRepository extends Mock implements Repository {}

final sideEffectAsyncNotifierProvider =
    AsyncNotifierProviderFamily<SideEffectAsyncNotifier, int, int>(
  SideEffectAsyncNotifier.new,
);

class SideEffectAsyncNotifier extends FamilyAsyncNotifier<int, int> {
  @override
  FutureOr<int> build(int initialValue) => initialValue;

  Repository get repository => ref.watch(repositoryProvider);

  void increment() {
    repository.sideEffect();
    state = AsyncData(value + 1);
  }
}

testResultProvider

testResultProvider<Repository>(
  'expect [1] when incrementCounter is called',
  provider: repositoryProvider,
  act: (result) => result.incrementCounter(),
  expect: () => [1],
);

final repositoryProvider = Provider<Repository>((ref) => Repository());

class Repository {
  int incrementCounter() => 1;
}

testStateNotifier

testStateNotifier<CounterStateNotifier, int>(
  'expect [0] when decrement is called and seed: 1',
  provider: counterStateNotifierProvider,
  act: (notifier) => notifier.decrement(),
  seed: 1,
  wait: const Duration(milliseconds: 100),
  expect: () => <int>[0],
);

final counterStateNotifierProvider =
    StateNotifierProvider<CounterStateNotifier, int>(
  (ref) => CounterStateNotifier(),
);

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

  void increment() => state++;

  Future<void> decrement() async {
    await Future<void>.delayed(const Duration(milliseconds: 100));
    state--;
  }
}

श्रेणियाँ

निर्भरताएँ

निर्भरता सूची 4 आइटम

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट

अभी कोई डेटा उपलब्ध नहीं है।