Unit testing in Flutter passing BuildContext. One way is to use testWidgets in combination with a Builder widget:
1 2 3 4 5 6 7 8 9 10 11 12 13 | testWidgets('me testing', (WidgetTester tester) async { await tester.pumpWidget( Builder( builder: (BuildContext context) { var actual = sut.myMethodName(context, ...); expect(actual, something); // The builder function must return a widget. return Placeholder(); }, ), ); }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.