1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +00:00

[testing_app] Migrate the sample to the integration_test package (#633)

This commit is contained in:
Abdullah Deshmukh
2021-01-31 12:17:22 +05:30
committed by GitHub
parent d16d35e0ac
commit f63c465ff4
15 changed files with 301 additions and 626 deletions

View File

@@ -0,0 +1,50 @@
// 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';
Favorites favoritesList;
Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
create: (context) {
favoritesList = Favorites();
return favoritesList;
},
child: 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);
});
});
}