# TestFailure: Golden image dimensions do not match: expected 1080x1920, actual 720x1280

- **ID:** `flutter/golden-test-image-size-mismatch`
- **Domain:** flutter
- **Category:** test_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The golden file used for image comparison has different dimensions than the rendered widget, often due to a change in screen size, widget layout, or test device configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Flutter 3.10.0 | active | — | — |
| Flutter 3.19.0 | active | — | — |
| Dart 3.0.0 | active | — | — |

## Workarounds

1. **Regenerate the golden file by running the test with the '--update-goldens' flag. Example:
  flutter test --update-goldens test/widget_test.dart
This overwrites the golden file with the current rendered output.** (90% success)
   ```
   Regenerate the golden file by running the test with the '--update-goldens' flag. Example:
  flutter test --update-goldens test/widget_test.dart
This overwrites the golden file with the current rendered output.
   ```
2. **Ensure the test widget is rendered at the same size as the golden. In the test, set a fixed surface size using:
  testWidgets('golden test', (tester) async {
    await tester.binding.setSurfaceSize(Size(1080, 1920));
    await tester.pumpWidget(MyWidget());
    await expectLater(find.byType(MyWidget), matchesGoldenFile('golden.png'));
  });** (85% success)
   ```
   Ensure the test widget is rendered at the same size as the golden. In the test, set a fixed surface size using:
  testWidgets('golden test', (tester) async {
    await tester.binding.setSurfaceSize(Size(1080, 1920));
    await tester.pumpWidget(MyWidget());
    await expectLater(find.byType(MyWidget), matchesGoldenFile('golden.png'));
  });
   ```
3. **Check for responsive layout changes that alter widget dimensions; wrap the widget in a SizedBox with fixed size in the test to match the golden.** (80% success)
   ```
   Check for responsive layout changes that alter widget dimensions; wrap the widget in a SizedBox with fixed size in the test to match the golden.
   ```

## Dead Ends

- **Update the golden file manually by copying the actual output to the golden directory** — If the layout change is unintended, copying the output introduces a false positive; the test passes but the UI is broken. (60% fail)
- **Set a fixed screen size in the test using TestWidgetsFlutterBinding** — Fixing the screen size may not match the golden's expected dimensions; the dimensions must align exactly. (50% fail)
- **Use 'matchGoldenFile' with a tolerance parameter to ignore size differences** — The 'matchGoldenFile' method does not have a tolerance parameter for dimensions; it only compares pixel data after resizing, which can cause blurry comparisons. (80% fail)
