Dart unit tests: test package, fakes and async expectations

10 steps · about 3 h 15 min · Intermediate

  1. Dart testing (doc, dart.dev, 10 min)

    Starts with the official map of unit, component and end-to-end tests, so you know what a unit test is for.

  2. Dart tutorial: Testing (site-www) (tutorial, dart-lang/site-www, 30 min)

    A hands-on first pass: add the dev dependency, create a test file, and run dart test on real data models.

  3. Unit Testing in Dart - Writing Clean and Reliable Tests (article, Dart Code Labs, 20 min)

    Reinforces the arrange-act-assert structure and shows a test around a class with a dependency.

  4. An introduction to unit testing (guide, Flutter docs, 15 min)

    A short official recipe covering file layout, test() and expect(), and the _test.dart naming convention.

  5. dart-lang/test: A library for writing unit tests in Dart (reference, dart-lang/test on GitHub, 15 min)

    Shows the package family (test, matcher, fake_async, checks) so you know which tool does what.

  6. test 1.16.8 (reference, pub.dev, 25 min)

    The package readme explains async tests, completion(), throwsA and stream matchers. This is an older version, so check the latest readme for newer features.

  7. How to Write Tests using Stream Matchers and Predicates in Flutter (article, Code With Andrea, 20 min)

    Explains why expect is too late for streams, and when to use expectLater with emitsInOrder and whether to await it.

  8. Dart Mocking: Enhancing Unit Tests with Mock Objects (article, Coddy, 15 min)

    Introduces fakes and mocks with mockito: implement the dependency, stub async answers, and test Streams.

  9. Flutter Testing Strategy: Unit, Widget & Integration Tests (article, Flutter Studio, 25 min)

    Compares mocktail and mockito, then uses fakeAsync to control timers deterministically, which suits the last step.

  10. Testing BLoC in Flutter (article, DEV Community, 20 min)

    A worked example that combines stubbed API fakes with emitsInOrder to test loading, empty and error states.