Skip to content

shirsh94/golden_test

Repository files navigation

Golden Test in Flutter


Project Name: Golden Test in Flutter

Overview:

Golden Test in Flutter is a testing methodology that focuses on ensuring the visual appearance of your Flutter app. Unlike traditional tests that verify code logic, golden tests capture snapshots of your app's UI and compare them to reference images (golden files). This helps not only in confirming correct functionality but also in maintaining the desired visual aesthetics.

How Golden Tests Work:

Flutter caches UI images, later comparing pixel by pixel for testing. This involves creating golden files, which act as visual reference points. These files are compared to newly rendered UI elements, ensuring that any changes do not unintentionally alter the app's visual output.

Getting Started:

To create golden files in Flutter, follow these steps:

  1. Generate images for all Golden tests or update existing ones:
    flutter test --update-goldens
  2. Look for the generated counter.png file in your project's test folder and add it to version control.

Example - Simple Counter App:

Check the golden_widget_test.dart file inside the test folder for an example implementation of a golden test. This file uses the testWidgets function for widget testing and compares the rendered appearance of a widget with a pre-existing golden image.

Running Tests:

To run golden tests:

flutter test

GitHub Repository:

GitHub - shirsh94/golden_test

Contribute by creating an account and adding your insights or improvements.

Considerations:

  • Storage: Golden tests continuously generate image files, so consider storage challenges. Storing them in a Git repository is an option but may not be ideal for projects with numerous tests.
  • False Positives: Minor pixel differences may trigger failures, so be cautious of potential false positives.
  • Component-Level Testing: Golden tests are more effective for verifying components than entire screens. Focus on component-level testing for optimal reliability.

Connect with the Developer:

Support and Feedback:

Your support is appreciated! If you find any issues or have suggestions for improvement, please mention them in the comments. Subscribe to the YouTube channel for more content.

About the Developer:

Shirsh Shukla is a creative Developer and Technology lover. Connect on LinkedIn or Twitter, and explore the portfolio for more details.

Have a Nice Day! 🙂

Shirsh Shukla is All about Flutter 💙💙💙💙


Note: Golden Test in Flutter is a valuable tool for detecting regressions and rendering issues. Carefully consider storage and potential false positives, and focus on component-level testing for optimal reliability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published