To get started, we simply need to import flutter_test , and the mockito package along with our authentication bloc. In our setUp , we instantiate a new instance of AuthenticationBloc to ensure that each test is run under the same conditions and does not influence subsequent tests. In addition, we are using mockito to create a mock instance of the UserRepository which is a dependency of the AuthenticationBloc.

Our first test is just testing that our initialState is what we expect…nothing too fancy. Our second test is just a sanity check as well to make sure that when close is called the state of the bloc is not updated.

After running flutter test our first two tests should be passing!

The remaining tests are what we really care about. If we take the AppStarted group as an example, all we need to do is setup our expectation of what events the bloc will yield. In this case, when we add an AppStarted event, we expect that the bloc will yield an AuthenticationUninitialized state followed by an AuthenticationUnauthenticated state because we have mocked our UserRepository return false for hasToken .

The remaining groups have very similar flows and should all make sense now.