Repository: flutter/flutter
File: packages/flutter/test/material/carousel_test.dart (Dart)

Code before:
                child: Center(child: Text('Item $index')),
              );
            },
          ),
        ),
      ),
    );

    // Only visible items should be built initially.
    expect(builtItems.length, lessThan(10));
    expect(builtItems, contains(0));
    expect(builtItems, contains(1));

    // Scroll to a far item.
    await tester.drag(find.byType(CarouselView), const Offset(-2000.0, 0.0));
    await tester.pumpAndSettle();

    // Clear built items to see what's built after scrolling.
    builtItems.clear();

    // Force rebuild by scrolling a bit more.
    await tester.drag(find.byType(CarouselView), const Offset(-300.0, 0.0));
    await tester.pump();

    // Should have built new items, not the initial ones.
    expect(builtItems.isNotEmpty, isTrue);
    expect(builtItems.every((int index) => index > 3), isTrue);
  });

  group('CarouselController.animateToItem', () {
    testWidgets('CarouselView.weighted horizontal, not reversed, flexWeights [7,1]', (
      WidgetTester tester,
    ) async {
      await runCarouselTest(
        tester: tester,
        flexWeights: <int>[7, 1],
        numberOfChildren: 20,
        scrollDirection: Axis.horizontal,
        reverse: false,
      );
    });

    testWidgets('CarouselView.weighted horizontal, reversed, flexWeights [7,1]', (
      WidgetTester tester,
    ) async {
      await runCarouselTest(
        tester: tester,
        flexWeights: <int>[7, 1],
        numberOfChildren: 20,
        scrollDirection: Axis.horizontal,
        reverse: true,

Review comment (bug):
I think you can do something like this and get a better error message when a failure happens:

```dart
expect(builtItems, isNotEmpty);
```

Code after:
                child: Center(child: Text('Item $index')),
              );
            },
          ),
        ),
      ),
    );

    // Only visible items should be built initially.
    expect(builtItems.length, lessThan(10));
    expect(builtItems, contains(0));
    expect(builtItems, contains(1));

    // Scroll to a far item.
    await tester.drag(find.byType(CarouselView), const Offset(-2000.0, 0.0));
    await tester.pumpAndSettle();

    // Clear built items to see what's built after scrolling.
    builtItems.clear();

    // Force rebuild by scrolling a bit more.
    await tester.drag(find.byType(CarouselView), const Offset(-300.0, 0.0));
    await tester.pump();

    // Should have built new items, not the initial ones.
    expect(builtItems, isNotEmpty);
    expect(builtItems.every((int index) => index > 3), isTrue);
  });

  group('CarouselController.animateToItem', () {
    testWidgets('CarouselView.weighted horizontal, not reversed, flexWeights [7,1]', (
      WidgetTester tester,
    ) async {
      await runCarouselTest(
        tester: tester,
        flexWeights: <int>[7, 1],
        numberOfChildren: 20,
        scrollDirection: Axis.horizontal,
        reverse: false,
      );
    });

    testWidgets('CarouselView.weighted horizontal, reversed, flexWeights [7,1]', (
      WidgetTester tester,
    ) async {
      await runCarouselTest(
        tester: tester,
        flexWeights: <int>[7, 1],
        numberOfChildren: 20,
        scrollDirection: Axis.horizontal,
        reverse: true,