Flutter testing resources

An opinionated guide to learning more about Flutter automated testing 🧪

March 9, 2022
March 9, 2022
updated on
March 9, 2023
Guest Contributor

Our team at VGV has a reputation for prioritizing automated testing in all of our projects, whether it’s an open source package or a production app for a client. We thought it might be helpful to gather our recommended testing resources — including blogs, courses, and packages — and put them all in one place here. Bookmark this page!

Table of Contents (click to skip to section):

Why should I write automated tests?

There are many benefits to writing automated tests. They can help you catch bugs, validate that your code works as intended, and give you confidence that every line of code you ship has been executed at least once (which is why we recommend 100% line coverage). Simply put: writing automated tests can ensure that your code is high-quality.

This tweet by Gergely Orosz says it best:

Do your team (and future you) a favor and write automated tests!

Where can I read about automated testing?

One of the best places to learn about testing is the Flutter documentation itself. Here are a couple of pages we recommend to start:

There are also many blogs that explore automated testing and provide examples of how to write tests. Here are articles that we suggest reading, including some from our blog:

Where can I find videos or courses about automated testing in Flutter?

The below resources are great for both beginners wanting to learn the fundamentals and experienced devs looking to brush up on their testing skills.

What packages should I use for automated testing?

These are some packages we frequently use to write unit, widget, and integration tests in our Flutter projects. Most of the tools listed were developed by our team to help make automated testing easy:

  • Very Good Coverage: Essential for enforcing a minimum code coverage threshold for your projects (we recommend 100%).
  • Very Good Workflows: Run your tests as part of these reusable GitHub workflows. Includes support for Flutter projects, Flutter packages, and Dart packages.
  • Very Good CLI: Generate a fully-tested scalable starter app, package, or plugin with our CLI tool. You can also use the very_good test command to run tests directly from the command line.
  • Mocktail: Inspired by mockito, this package helps you create mocks in Dart with null safety without the need for manual mocks or code generation.
  • Bloc Test: Test your blocs easily with this package. It is especially useful if you’re using bloc and mocktail in your projects.
  • Flame Test: Test your applications using Flame with these classes.
  • Mockingjay: Mock navigation in Flutter for testing purposes.
  • Alchemist: A package built by Betterment in collaboration with VGV that makes it easy to write golden tests, complete with useful functions, extensions, and documentation.

Does test coverage matter?

Yes! Our answer will always be to aim for 100% test coverage. We recognize that this is a high threshold and we hold ourselves to it whenever possible. It's important to note 100% test coverage does not guarantee the codebase is bug-free. We use 100% as our threshold because it ensures every line of code we ship has been exercised by at least one test.

However, we also know that teams have their own requirements and sometimes 100% coverage is not possible to achieve. In these cases, we recommend two things:

  1. Starting today, make it a requirement to write tests with every pull request.
  2. Decide with your team on a coverage threshold and stick to it (Very Good Coverage can help you with this).

The important thing is that you adhere to the coverage threshold you set and always aim to improve. If you set your threshold at 80%, make it a goal to never drop below. Instead, maintain that threshold or even better, gradually raise it over time until you can reach 100%.

Are there examples of fully-tested apps?

For examples of fully-tested Flutter apps, check out these open source examples:

What about CI/CD?

Automated testing is not complete without a robust CI/CD solution. When it comes to CI/CD we highly recommend the following tools:

GitHub Actions: GitHub Actions are extremely useful for automating everything from checking your spelling to running your automated tests. Check out the GitHub Actions Marketplace to browse the available actions. Note: Very Good Workflows is a GitHub Action that can automatically run all of your tests on each PR.

CI/CD Solutions:

  • Codemagic:* This is our preferred continuous deployment solution for Flutter apps. Other solutions that work great with Flutter apps include AppWrite, Bitrise, Jenkins, Circle CI, and more. These are great because they are fully managed solutions, which allow you to run tests and other automated steps without having to manage your own servers. In addition, Codemagic makes it extremely easy to distribute your app via Google Play and TestFlight. *Note that VGV gets a portion of sales when we refer clients to Codemagic.
  • Firebase Test Lab: Allows you to run tests on different hardware devices in a Google data center so that you can be sure your apps run as expected on all of the devices you're targeting.

Felix Angelov contributed to this article.

For more on our best practices, check out this article about building scalable apps.

More Stories