Testing in Flutter

Unit tests:

You can use the flutter_test library. Cheat sheet below

  • group((String) description, () {}) – function allows you to create a group of tests. The tests go inside the curly braces, of course.
  • test((String) description, () {}) – inside the group body, used to run a synchronous test
  • testWidget((String) description, () async {}) – also inside the group body, used to run an async test. (I believe it doesn’t *have* to run an async test, but it’s useful for that)
  • expect(actual, matcher) – use inside of a test. You can have the matcher be a constant like findsOneWidget (since both actual and matcher are dynamic)
  • WidgetTester – class that handles widgets in the testing environment. Can use pumpWidget or pumpAndSettle to render the widgets in the test environment. This can let you test if the UI is displaying correctly (eg if you add something to a displayed list, does it show up?)

Integration Tests:

Misc things learned:

Leave a comment