Skip to content

Creating test implementation of AssetBundle is tricky and will likely result in errors that are difficult to understand #126860

@andrewkolos

Description

@andrewkolos

See #126612.

If unfamiliar with the concept of assets in Flutter, see Adding assets and images.

TL;DR: There are multiple users that use fake/mock/stub implements of AssetBundle in tests. AssetBundle is used for loading assets in flutter apps. Nearly all assets in a bundle are ones that user chooses to include, but the framework also bundles its own asset, the asset manifest. This means that users need to handle the call to load the asset manifest in their load override, but it's unlikely that they will be aware of this (or even what the asset manifest is).

While there is perhaps a greater discussion to be had around whether or not flutter bundling files (namely the asset manifest) with an app should have the ability to break these tests, we can perhaps start with something smaller to help these users. Here are some suggestions, none of which are mutually exclusive:

  • In the call to load the asset manifest, we can catch the vague FormatException and augment the message with a more useful note.
  • Improve the documentations of DefaultAssetBundle, which is (probably) commonly used to provide/inject test implementations of AssetBundle. We could make an explicit note about how to override this for custom tests, and/or we could could consider changing the example code to look more like one of the examples on this comment on #126612 (thanks @eerive).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: assetsPackaging, accessing, or using assetsc: tech-debtTechnical debt, code quality, testing, etc.team-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy