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?
- Where can I read about automated testing?
- Where can I find videos or courses about automated testing in Flutter?
- What packages should I use for automated testing?
- Does test coverage matter?
- Are there examples of fully-tested apps?
- What about CI/CD?
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:
- Flutter docs: Testing Flutter apps: The official documentation for automated testing with Flutter. Learn about unit, widget, and integration tests here.
- Flutter docs: How to test a Flutter app codelab: Learn how to test a Flutter app with this interactive codelab.
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:
- How can I start with Flutter Testing? by Ana Polo: Read about a Flutter developer's journey to learn more about Flutter testing.
- Flutter testing: A very good guide by VGV: Learn about VGV's approach to the what, how, and why of Flutter testing.
- How to use Alchemist for Flutter golden tests by VGV: Learn how to use the package Alchemist (created by Betterment x VGV) to write golden tests for your Flutter projects.
- Robot Testing by VGV: Read about the Robot Testing method for end-to-end testing.
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.
- Testing Fundamentals of Flutter by Jorge Coca for VGV: In just over 30 minutes, you can learn the basics about widget, unit, and integration tests.
- Widget Testing by Jorge Coca for Google Developer Experts: This is a great standalone video that teaches how to use widget tests in your Flutter projects.
- Flutter Testing Guide for Beginners by ResoCoder: This new course will teach you how to make the most of automated testing in Flutter. As of the day this was published, Parts 1 and 2 are available; we anticipate that others will be published in the future.
- Unit Testing our AuthService by Vandad Nahavandipoor: This video is Chapter 26 in a free course that aims to take students from beginners to more experienced Flutter developers. Watch to learn how to write unit tests for a sample app.
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:
- Starting today, make it a requirement to write tests with every pull request.
- 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.