flutter_test_utils

Last updated:

0 purchases

flutter_test_utils Image
flutter_test_utils Images
Add to Cart

Description:

flutter test utils

Flutter Test Utils #
A set of helper methods for testing widgets in the Flutter framework.
Installation #
In your pubspec.yaml file, add the following dependency:
dependencies:
flutter_test_utils: ^1.0.0
copied to clipboard
Then, run flutter pub get to install the package.
Usage #
Import the package in your test file:
import 'package:flutter_test_utils/flutter_test_utils.dart';
Then, you can use any of the available helper methods in your test cases. Here are the currently available helper methods:
waitForWidget #
This method waits until a widget is found in the widget tree before running tests. This is useful when testing asynchronous operations such as network calls or animations.
Example usage:
testWidgets('Test widget with future', (WidgetTester tester) async {
final widget = MyWidgetWithFuture();
await FlutterTestUtils.waitForWidget(find.byType(MyWidget), tester);
expect(find.byType(MyWidgetWithFuture), findsOneWidget);
});
copied to clipboard
pumpWidgetWithAnimation #
This is a method for testing widget animations. This method wraps the tester.pumpWidget method with a loop that allows testing widget animations over time.
Example usage:
testWidgets('Test widget animation', (WidgetTester tester) async {
final widget = MyWidget();
await FlutterTestUtils.pumpWidgetWithAnimation(widget, tester);
expect(find.byType(MyWidget), findsOneWidget);
});
copied to clipboard
testWidgetState #
Tests the state of a widget after a duration of time. This method wraps the tester.pumpAndSettle method with a loop that allows testing the widget state over time.
Example usage:
testWidgets('Test widget state', (WidgetTester tester) async {
final widget = MyWidget();
await FlutterTestUtils.testWidgetState(widget, tester);
expect(find.byType(MyWidget), findsOneWidget);
});
copied to clipboard
testWidgetTap #
Tests the behavior of a widget when an item is tapped.
Example usage:
testWidgets('Test widget tap', (WidgetTester tester) async {
final widget = MyWidget();
await FlutterTestUtils.testWidgetTap(widget, tester);
expect(find.byType(MyOtherWidget), findsOneWidget);
});
copied to clipboard
testWidgetLongPress #
This is a method for testing the behavior of a widget when an item is long-pressed.
Example usage:
testWidgets('Test widget long press', (WidgetTester tester) async {
final widget = MyWidget();
await FlutterTestUtils.testWidgetLongPress(widget, tester);
expect(find.byType(MyOtherWidget), findsOneWidget);
});
copied to clipboard
testWidgetScroll #
This is a method for testing the behavior of a widget when an item is scrolled.
Example usage:
testWidgets('Test widget scroll', (WidgetTester tester) async {
final widget = MyWidget();
await FlutterTestUtils.testWidgetScroll(widget, tester, 100.0);
expect(find.byType(MyOtherWidget), findsOneWidget);
});
copied to clipboard
testWidgetDialog(WidgetTester tester, Finder dialogFinder) #
Tests the presence of a dialog in the widget tree.
Example usage:
await FlutterTestUtils.testWidgetDialog(tester, find.byType(Dialog));
expect(find.byType(Dialog), findsOneWidget);
copied to clipboard
testWidgetSnackbar(WidgetTester tester, String snackbarText) #
Tests the presence of a snackbar in the widget tree.
Example usage:
final snackbarText = 'Snackbar text';
await FlutterTestUtils.testWidgetSnackbar(tester, snackbarText);
expect(find.text(snackbarText), findsOneWidget);
copied to clipboard
testWidgetAbsence(WidgetTester tester, Finder widgetFinder) #
Tests the absence of a widget in the widget tree.
Example usage:
final widget = MyWidget();
await tester.pumpWidget(widget);
await FlutterTestUtils.testWidgetAbsence(tester, find.byType(SnackBar));
expect(find.byType(SnackBar), findsNothing);
copied to clipboard
Contributing #
If you find any bugs or have any suggestions for improvements, feel free to open an issue or a pull request on the GitHub repository. Contributions are always welcome!
License #
This package is licensed under the MIT License. See the LICENSE file for more information.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.