<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr" -->

---
title: How to Test Flutter Apps: Unit, Widget, Golden, and...
description: A practical walkthrough of the four Flutter testing layers—unit, widget, golden, and integration tests—built around a single task-completion feature so readers...
canonical: https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Test Flutter Apps: Unit, Widget, Golden, and Integration Tests Explained | daily.dev
og:description: A practical walkthrough of the four Flutter testing layers—unit, widget, golden, and integration tests—built around a single task-completion feature so readers...
og:url: https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr
og:image: https://api.daily.dev/og/posts/FgHi4b2tR.png
og:image:alt: How to Test Flutter Apps: Unit, Widget, Golden, and Integration Tests Explained
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Test Flutter Apps: Unit, Widget, Golden, and Integration Tests Explained

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 27 min read · 0 upvotes · 0 comments

## Summary

A practical walkthrough of the four Flutter testing layers—unit, widget, golden, and integration tests—built around a single task-completion feature so readers see how the layers fit together rather than viewing disconnected snippets. Covers mocktail for fakes, golden_toolkit for multi-device and dark-mode visual regression testing, common widget-test mistakes (pump vs pumpAndSettle, missing MaterialApp wrappers, brittle text finders), flaky integration test handling, and a full GitHub Actions pipeline that gates unit/widget tests, golden tests, and integration tests in sequence by cost.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained>

## Questions this post answers

### What is the difference between pump() and pumpAndSettle() in Flutter widget tests?

pump() advances the test by exactly one frame, useful for catching a transient state like a loading spinner mid-flight, while pumpAndSettle() keeps pumping frames until nothing is scheduled to rebuild, which is right for asserting on a final settled state. pumpAndSettle() will hang and eventually time out if the widget tree contains something that animates continuously, such as a CircularProgressIndicator, so pump() or pump(duration) should be used instead in that case.

_daily.dev surfaces practical fixes like this for developers debugging flaky Flutter widget tests._

### How do I write a golden test for a Flutter widget across multiple screen sizes and dark mode?

Use golden_toolkit's multiScreenGolden or DeviceBuilder with overrideDevicesForAllScenarios to render the same widget across several device sizes, such as Device.phone, Device.iphone11, and Device.tabletLandscape, in one test via pumpDeviceBuilder and screenMatchesGolden. For dark mode, pump the widget with materialAppWrapper(theme: ThemeData.dark()) and compare against a separate golden file, since a hardcoded text color invisible on dark backgrounds won't show up in a light-mode-only golden.

_Developers setting up visual regression coverage can track Flutter and testing tool changes on daily.dev._

### Why does my Flutter test pass even though the async function actually throws an error?

Writing expect(() => someAsyncFunction(), throwsA(...)) without await lets the synchronous expect() run before the Future's exception resolves, so the test passes even when the code is broken. The fix is using expectLater combined with await, which actually waits for the async failure to occur before making the assertion, ensuring the failure path is genuinely exercised.

_daily.dev helps Flutter developers keep up with testing patterns like async exception handling in Dart._

## Similar posts on daily.dev

- [How to Test AI Features in Flutter \[Full Handbook\]](https://daily.dev/posts/how-to-test-ai-features-in-flutter-full-handbook--xpmis9o30) · freeCodeCamp · 2 upvotes · 0 comments
- [TDD is a Luxury: Pragmatic Testing for the Solo Developer](https://daily.dev/posts/tdd-is-a-luxury-pragmatic-testing-for-the-solo-developer-tawfchoo4) · Ruby Flow · 0 upvotes · 1 comments
- [Medium](https://daily.dev/posts/medium-vglich5gj) · Medium · 0 upvotes · 0 comments
- [A Practical Guide to Flutter Accessibility — Part 1: The Basics](https://daily.dev/posts/a-practical-guide-to-flutter-accessibility-part-1-the-basics-ciuqrpxcj) · ITNEXT · 0 upvotes · 0 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#cicd](https://daily.dev/tags/cicd), [#flutter](https://daily.dev/tags/flutter), [#dart](https://daily.dev/tags/dart)

[View this post on daily.dev](https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Test Flutter Apps: Unit, Widget, Golden, and Integration Tests Explained","url":"https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr"},"datePublished":"2026-08-27T22:50:36.339Z","dateModified":"2026-09-14T08:22:35.009Z","description":"A practical walkthrough of the four Flutter testing layers—unit, widget, golden, and integration tests—built around a single task-completion feature so readers...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fa4ab02e34e613cf5d1bf2b931d05d83?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fa4ab02e34e613cf5d1bf2b931d05d83?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"freeCodeCamp","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1628412854/logos/freecodecamp","url":"https://daily.dev/sources/freecodecamp"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,cicd,flutter,dart","timeRequired":"PT27M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"How to Test Flutter Apps: Unit, Widget, Golden, and Integration Tests Explained"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-test-flutter-apps-unit-widget-golden-and-integration-tests-explained-fghi4b2tr#faq","mainEntity":[{"@type":"Question","name":"What is the difference between pump() and pumpAndSettle() in Flutter widget tests?","acceptedAnswer":{"@type":"Answer","text":"pump() advances the test by exactly one frame, useful for catching a transient state like a loading spinner mid-flight, while pumpAndSettle() keeps pumping frames until nothing is scheduled to rebuild, which is right for asserting on a final settled state. pumpAndSettle() will hang and eventually time out if the widget tree contains something that animates continuously, such as a CircularProgressIndicator, so pump() or pump(duration) should be used instead in that case. daily.dev surfaces practical fixes like this for developers debugging flaky Flutter widget tests."}},{"@type":"Question","name":"How do I write a golden test for a Flutter widget across multiple screen sizes and dark mode?","acceptedAnswer":{"@type":"Answer","text":"Use golden_toolkit's multiScreenGolden or DeviceBuilder with overrideDevicesForAllScenarios to render the same widget across several device sizes, such as Device.phone, Device.iphone11, and Device.tabletLandscape, in one test via pumpDeviceBuilder and screenMatchesGolden. For dark mode, pump the widget with materialAppWrapper(theme: ThemeData.dark()) and compare against a separate golden file, since a hardcoded text color invisible on dark backgrounds won't show up in a light-mode-only golden. Developers setting up visual regression coverage can track Flutter and testing tool changes on daily.dev."}},{"@type":"Question","name":"Why does my Flutter test pass even though the async function actually throws an error?","acceptedAnswer":{"@type":"Answer","text":"Writing expect(() =\u003e someAsyncFunction(), throwsA(...)) without await lets the synchronous expect() run before the Future's exception resolves, so the test passes even when the code is broken. The fix is using expectLater combined with await, which actually waits for the async failure to occur before making the assertion, ensuring the failure path is genuinely exercised. daily.dev helps Flutter developers keep up with testing patterns like async exception handling in Dart."}}]}
```

