שמרו על בדיקות דטרמיניסטיות עם containers מפורשים.

רוב תרחישי הבדיקה ממופים ישירות ל-API של ProviderContainer: read, invalidate, refresh, listen ו-overrides לכל מופע provider.

Test Strategy

חלקו את הבדיקות לבדיקות container טהורות ולבדיקות אינטגרציה של widgets.

Pure Dart

השתמשו ב-ProviderContainer ישירות עבור טענות read/invalidate/refresh

Overrides

דרסו לפי מופע provider בעזרת overrideWith / overrideWithValue

Widget tests

הזריקו container חיצוני ופנו אותו במפורש

Tip

ProviderContainer.listen לא פולט את הערך ההתחלתי אלא אם fireImmediately: true מצוין.

פקודת בדיקה ורשימת בדיקה

הריצו את כל החבילה ובדקו שאין דליפות timer ממתינות בתרחישי autoDispose.

Command

Checklist

- Dispose externally injected ProviderContainer in tearDown.
- Use fireImmediately: true when your listener assertions need initial state.
- For autoDispose tests, advance fake time beyond autoDisposeDelay.

דוגמה: override לפי ארגומנט

providers דמויי-משפחה נדרסים לכל מופע שנוצר על ידי פונקציית ה-factory שלכם.

class ProductById extends Provider<Product> {
  ProductById(this.id) : super.args((id,));
  final String id;

  @override
  Product build(ref) {
    final repo = ref.watch(productRepoProvider);
    return repo.fetch(id);
  }
}

final container = ProviderContainer(
  overrides: [
    productByIdProvider('a').overrideWithValue(const Product(id: 'a', name: 'stub')),
  ],
);

// assert and cleanup
container.dispose();
התבנית הזו משקפת את README ואת בדיקות ה-upstream במאגר miniriverpod.
בדיקות widgets צריכות לפרק widgets לפני שמפנים containers חיצוניים.
השתמשו ב-fake_async כדי לאמת עיכובי autoDispose והתנהגות keepAlive.

השלבים הבאים

API Reference

פתחו חתימות מהירות עבור ProviderContainer, Ref, AsyncValue ו-API של mutation.

Open API Reference

Back to Overview

חזרו למפת התיעוד המלאה של miniriverpod.

Open Overview