How best to stub/mock rest API calls in Flutter Integration tests

Posted by Pinki | Updated on

How best to stub/mock rest API calls in Flutter Integration tests. Here’s the approach I went with: Create a mock client that uses the Dart http MockClient:

Now you need to pass your mock client into your app, when you start up your app in integration tests e.g. test_driver/app.dart

You may need to refactor your non-test code so that when the app starts up, you can inject a client. Either a real client or a mock client when testing.


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.

Related Questions & Answers