Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spkersten/flutter_test_ui
Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions
https://github.com/spkersten/flutter_test_ui
flutter testing ui
Last synced: about 15 hours ago
JSON representation
Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions
- Host: GitHub
- URL: https://github.com/spkersten/flutter_test_ui
- Owner: spkersten
- License: mit
- Created: 2020-05-09T12:43:19.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-24T11:44:33.000Z (over 1 year ago)
- Last Synced: 2025-01-31T21:11:28.743Z (12 days ago)
- Topics: flutter, testing, ui
- Language: Dart
- Homepage: https://pub.dev/packages/flutter_test_ui
- Size: 8.79 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_test_ui
Wrapper of `testWidgets`, `setUp`, and `tearDown` that provide the `WidgetTesterCallback` argument
to the set-up and tear-down functions: `testUI`, `setUpUI`, and `tearDownUI`.This allows a single set-up to be shared by several tests and the set-up to be continued in subgroups.
In particular, it allows test to be written in rspec style for better readability.```dart
group("testUI and setUpUI example test", () {
setUpUI((tester) async {
await tester.pumpWidget(MaterialApp(
home: Builder(
builder: (context) => GestureDetector(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Container(
color: Colors.green,
child: const Text("page 2"),
),
),
),
child: Container(
color: Colors.red,
child: const Text("page 1"),
),
),
),
));
});testUI("first page is shown", (tester) async {
expect(find.text("page 1"), findsOneWidget);
});group("tapping the text", () {
setUpUI((tester) async {
await tester.tap(find.text("page 1"));
await tester.pumpAndSettle();
});testUI("second page is shown", (tester) async {
expect(find.text("page 2"), findsOneWidget);
});group("pop the second page", () {
setUpUI((tester) async {
final nav = tester.state(find.byType(Navigator));
nav.pop();
await tester.pumpAndSettle();
});testUI("second page isn't visible anymore", (tester) async {
expect(find.text("page 2"), findsNothing);
});testUI("first page is visible again", (tester) async {
expect(find.text("page 1"), findsOneWidget);
});
});
});
});
```