Exercise: Testing ShoppingCartCubit
Test your knowledge of writing tests for BLoCs.
We'll cover the following
Problem statement
In this exercise, test the ShoppingCartCubit
by doing the following:
Inside test/bloc_test.dart
:
Create a mock for the
ShoppingCartCubit
.Stub the
ShoppingCartCubit
, and test the stream’s initial state and that it emits state in order.Create unit tests for all the functions inside
ShoppingCartCubit
: add the item to the cart, remove the item from the cart, and clear the cart.
You can find the ShoppingCartCubit
inside lib/cubits/shopping_cart/shopping_cart_cubit.dart
.
The following functions are already defined below:
shoppingCart()
andshoppingCart1()
for theShoppingCartCubit
mock group.shoppingCartItem()
,emptyCart()
, andcartWithAProduct()
for theShoppingCartCubit functions
group.
Get hands-on with 1200+ tech skills courses.