Throws an Exception if the http call fails

Therefore, you want to test these two conditions.
Use the MockClient class to return an “Ok” response
for the success test, and an error response for the unsuccessful test.
Test these conditions using the when() function provided by
Mockito:

5. Run the tests

Now that you have a fetchAlbum() function with tests in place,
run the tests.

flutter

test test/fetch_album_test.dart

You can also run tests inside your favorite editor by following the
instructions in the Introduction to unit testing recipe.

Complete example

lib/main.dart

test/fetch_album_test.dart

Summary