snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 01:43:26 +05:00
commit 9ed6a80afa
2886 changed files with 140184 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
// Copyright 2020 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:testing_app/main.dart';
void main() {
group('Testing App Driver Tests', () {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Finding an item in the list', (tester) async {
await tester.pumpWidget(const TestingApp());
// Create variables for finders that are used multiple times.
final itemFinder = find.byKey(const ValueKey('text_25'));
// Scroll until the item to be found appears.
await tester.scrollUntilVisible(itemFinder, 500.0);
// Check if the item contains the correct text.
expect(tester.widget<Text>(itemFinder).data, 'Item 25');
});
testWidgets('Testing IconButtons', (tester) async {
await tester.pumpWidget(const TestingApp());
// Create a finder for the icon.
final iconFinder = find.byKey(const ValueKey('icon_0'));
// Tap on the icon.
await tester.tap(iconFinder);
// Wait 1 second for the SnackBar to be displayed
await tester.pumpAndSettle(const Duration(seconds: 1));
// Verify if appropriate message appears.
expect(find.text('Added to favorites.'), findsOneWidget);
// Tap on the icon again.
await tester.tap(iconFinder);
// Wait 1 second for the SnackBar to be displayed
await tester.pumpAndSettle(const Duration(seconds: 1));
// Verify if appropriate message appears.
expect(find.text('Removed from favorites.'), findsOneWidget);
});
testWidgets('Verifying whether item gets added to favorites', (
tester,
) async {
await tester.pumpWidget(const TestingApp());
// Add item to favorites.
await tester.tap(find.byKey(const ValueKey('icon_5')));
await tester.pumpAndSettle();
// Tap on the favorites button on the AppBar.
// The Favorites List should appear.
await tester.tap(find.text('Favorites'));
await tester.pumpAndSettle();
// Check if the added item has appeared in the list.
expect(
tester
.widget<Text>(find.byKey(const ValueKey('favorites_text_5')))
.data,
equals('Item 5'),
);
});
testWidgets('Testing remove button', (tester) async {
await tester.pumpWidget(const TestingApp());
// Add item to favorites.
await tester.tap(find.byKey(const ValueKey('icon_5')));
await tester.pumpAndSettle();
// Navigate to Favorites screen.
await tester.tap(find.text('Favorites'));
await tester.pumpAndSettle();
// Tap on the remove icon.
await tester.tap(find.byKey(const ValueKey('remove_icon_5')));
// Wait 1 second for the SnackBar to be displayed
await tester.pumpAndSettle(const Duration(seconds: 1));
// Verify if it disappears.
expect(find.text('Item 5'), findsNothing);
// Verify if appropriate message appears.
expect(find.text('Removed from favorites.'), findsOneWidget);
});
});
}

View File

@@ -0,0 +1,7 @@
// Copyright 2020 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() => integrationDriver();

View File

@@ -0,0 +1,25 @@
// Copyright 2021 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:developer';
import 'package:integration_test/integration_test_driver.dart';
Future<void> main() {
return integrationDriver(
responseDataCallback: (data) async {
// If the tests reported any data, save it to the disk.
if (data != null) {
for (var entry in data.entries) {
log('Writing ${entry.key} to the disk.');
// Default storage destination is the 'build' directory.
await writeResponseData(
entry.value as Map<String, dynamic>,
testOutputFilename: entry.key,
);
}
}
},
);
}

View File

@@ -0,0 +1,96 @@
// Copyright 2020 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:testing_app/main.dart';
void main() {
group('Testing App Performance Tests', () {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// The fullyLive frame policy simulates
// the way Flutter responds to animations.
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
testWidgets('Scrolling test', (tester) async {
await tester.pumpWidget(const TestingApp());
// Create variables for finders that are used multiple times.
final listFinder = find.byType(ListView);
final scroller = tester.widget<ListView>(listFinder).controller;
// Record the performance summary as the app scrolls through
// the list of items.
await binding.watchPerformance(
() async {
// Quickly scroll all the way down.
await scroller!.animateTo(
7000,
duration: const Duration(seconds: 1),
curve: Curves.linear,
);
await tester.pumpAndSettle();
// Quickly scroll back up all the way.
await scroller.animateTo(
-7000,
duration: const Duration(seconds: 1),
curve: Curves.linear,
);
await tester.pumpAndSettle();
},
// Send the performance summary to the driver.
reportKey: 'scrolling_summary',
);
});
testWidgets('Favorites operations test', (tester) async {
await tester.pumpWidget(const TestingApp());
// Record the performance summary as operations are performed
// on the favorites list.
await binding.watchPerformance(
() async {
// Create a list of icon keys.
final iconKeys = ['icon_0', 'icon_1', 'icon_2'];
// Add first three items to favorites.
for (var icon in iconKeys) {
// Tap onto the icon.
await tester.tap(find.byKey(ValueKey(icon)));
await tester.pumpAndSettle(const Duration(seconds: 1));
// Verify if appropriate message appears.
expect(find.text('Added to favorites.'), findsOneWidget);
}
// Tap onto the favorites button on the AppBar.
// The Favorites List should appear.
await tester.tap(find.text('Favorites'));
await tester.pumpAndSettle();
final removeIconKeys = [
'remove_icon_0',
'remove_icon_1',
'remove_icon_2',
];
// Remove all the items from favorites.
for (final iconKey in removeIconKeys) {
// Tap onto the remove icon.
await tester.tap(find.byKey(ValueKey(iconKey)));
await tester.pumpAndSettle(const Duration(seconds: 1));
// Verify if appropriate message appears.
expect(find.text('Removed from favorites.'), findsOneWidget);
}
},
// Send the performance summary to the driver.
reportKey: 'favorites_operations_summary',
);
});
});
}

View File

@@ -0,0 +1,48 @@
// Copyright 2020 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:provider/provider.dart';
import 'package:testing_app/models/favorites.dart';
import 'package:testing_app/screens/favorites.dart';
late Favorites favoritesList;
Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
create: (context) {
favoritesList = Favorites();
return favoritesList;
},
child: const MaterialApp(home: FavoritesPage()),
);
void main() {
group('Testing App State Management Tests', () {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Verifying add method', (tester) async {
await tester.pumpWidget(createFavoritesScreen());
// Add an item to the list.
favoritesList.add(30);
await tester.pumpAndSettle();
// Check if the new item appears in the list.
expect(find.text('Item 30'), findsOneWidget);
});
testWidgets('Verifying remove method', (tester) async {
await tester.pumpWidget(createFavoritesScreen());
// Remove an item from the list.
favoritesList.remove(30);
await tester.pumpAndSettle();
// Verify if it disappears.
expect(find.text('Item 30'), findsNothing);
});
});
}