Menu

1 / 2

Flutter Golden Tests — Catch UI Regressions with Snapshot Testing

DEV Community·kanta13jp1·6 months ago
#NH28cYOA
#flutter#ai#indiedev#programming#test
Reading 0:00
15s threshold

Flutter Golden Tests — Catch UI Regressions with Snapshot Testing

Golden tests save a "expected UI image" and automatically compare it against future renders. They catch design regressions in CI before they ship.

Basic Golden Test

testWidgets ( 'PricingCard goldentest' , ( tester ) async { await tester . pumpWidget ( MaterialApp ( home: Scaffold ( body: PricingCard ( plan: PricingPlan ( name: 'Pro' , price: 2980 , highlight: true ), ), ), ), );

await expectLater ( find . byType ( PricingCard ), matchesGoldenFile ( 'goldens/pricing_card_pro.png' ), ); });

Enter fullscreen mode

Exit fullscreen mode

First run with flutter test --update-goldens generates the PNG.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.