Using Mockito in Flutter
Published in
5 min readMar 28, 2022
Using Mockito in Flutter
Article here: https://flatteredwithflutter.com/using-mockito-in-flutter/
We will cover briefly:
- Setup Mockito
- Mocking repository using Mockito
- Write unit tests for repository
- Write unit tests for the view model
- (Optional) Code coverage
Note: This article assumes the reader knows about unit testing
Setup Mockito
There are often times when unit tests depend on classes that fetch data from live web services or databases. This is inconvenient for a few reasons:
- Calling live services or databases slows down test execution.
- It is difficult to test all possible success and failure scenarios by using a live web service or database.