An introduction to unit testing

An introduction to widget testing

Mock dependencies using Mockito

Cookbook

Testing

Unit

Mocking

1. Add the package dependencies

2. Create a function to test

3. Create a test file with a mock http.Client

4. Write a test for each condition

5. Run the tests

Complete example

Summary

Sometimes, unit tests might 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.

A passing test might start failing if a web service or database returns
unexpected results. This is known as a “flaky test.”

It is difficult to test all possible success and failure scenarios
by using a live web service or database.