Skip to content

Instantly share code, notes, and snippets.

@tianhaoz95
Created October 23, 2019 19:37
Show Gist options
  • Save tianhaoz95/22a9006d6dc7623667402a2e3d8c437f to your computer and use it in GitHub Desktop.
Save tianhaoz95/22a9006d6dc7623667402a2e3d8c437f to your computer and use it in GitHub Desktop.
Basic widget testing
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'demo',
home: Scaffold(
appBar: AppBar(
title: Text('demo title'),
),
body: Center(
child: Text('demo content'),
),
),
);
}
}
void main() {
testWidgets('MyWidget has correct title and message', (WidgetTester tester) async {
await tester.pumpWidget(MyWidget());
final titleFinder = find.text('demo title');
final contentFinder = find.text('demo content');
expect(titleFinder, findsOneWidget);
expect(contentFinder, findsOneWidget);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment