“Flutter applications run on a single Isolate (Flutter doesn’t have threads, but Isolates) and the test execution is done in a separate Isolate that communicates with the application via a driver”.

Perhaps stating the obvious, but what is needed is to mock the data or information the app requires.

Mock objects are simulated objects that mimic the behaviour of real objects in controlled ways — Wikipedia.org

Mocking inside integration tests

An alternative could be MockWebServer from Square.

What’s blocking our mocking?

To mock each repository is a necessity because each test needs a concrete behaviour which the app should comply with. This behaviour also could change during test runtime.

DataHandler!

Every test expects one or more repositories to be mocked. We do not need to mock every repository, just what is needed for every test. The app Isolate is responsible for this, so all mocked repositories are going the be done by the app.

loading...
loading...

The driver is the one that sends the message and the DataHandler is the one listening in the app Isolate. Depending on the message received, we will be able to mock that a certain request returns a certain value.

The logic for understanding the message is required inside the DataHandler. This could be, as in this example, a string. Then a switch is used to cover all the different situations:

loading...

From this last piece of code we should clarify the “MockHelper”, from MockHelper.mockLoggedInSuccess();. This is a simple class that contains the required mocks:

loading...

The journey continues

This is our solution and we hope this helps anyone with the same needs.

Thanks to Victor Vargas, Rafael Visa, Sergi Castellsagué Millán, and Sean Handley. 

0 whoop whoops