A. Using expect instead of expectLater for matchesGoldenFile
B. Missing await before tester.pumpWidget
C. Incorrect widget type passed to find.byType
D. Golden file name should be a full path
Solution
Step 1: Check the matcher usage
Golden tests require expectLater with matchesGoldenFile to work asynchronously.
Step 2: Validate other parts
Await is correctly used with pumpWidget, widget type is correct, and relative file names are allowed.
Final Answer:
Using expect instead of expectLater for matchesGoldenFile -> Option A
Quick Check:
Golden test needs expectLater, not expect [OK]
Hint: Use expectLater, not expect, with matchesGoldenFile [OK]
Common Mistakes:
Using expect instead of expectLater
Forgetting async/await on pumpWidget
Assuming golden file needs full absolute path
5. You want to write a golden test for a button that changes color based on theme. Which approach ensures your golden test covers both light and dark themes correctly?
hard
A. Skip golden tests for theme changes and rely on manual testing
B. Write one golden test with default theme only, assuming dark theme looks similar
C. Write separate golden tests pumping the button with light and dark theme widgets and compare to separate golden files
D. Use a single golden file and toggle theme at runtime without repumping widget
Solution
Step 1: Understand theme impact on UI
Light and dark themes can change colors significantly, so testing both separately is needed.
Step 2: Evaluate testing approaches
Separate tests with repumping widgets under each theme and comparing to distinct golden files ensures accurate visual checks.
Final Answer:
Write separate golden tests pumping the button with light and dark theme widgets and compare to separate golden files -> Option C
Quick Check:
Test each theme separately with distinct golden files [OK]
Hint: Test light and dark themes separately with different golden files [OK]
Common Mistakes:
Assuming one golden file covers all themes
Not repumping widget after theme change
Skipping golden tests for theme variations
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.