Complete BLoC with Clean Architecture (group chat) Discount !! E-commerce App With Backend Source Code Video and Voice Chatting App Firebase Chatting App Source Code Complete Gym App BLoC State Management Source Code Complete Study App Buy Ticket Booking App Source Code Buy Travel App With Backend Source Code Complete Chat App Udemy Course Special Offer Discount !! Online Learning Course App (BLoC) Online Learning Course App (Riverpod) Online Learning Course App (Getx) Discount !! Shopping App (Provider) Cool Flutter Game Flutter Nodejs Chat App Flutter Nodejs Api And Firebase Chat App Riverpod Task Management App
Flutter BLoC or Cubit is one of the most popular for state management. We can use bloc_test package for unit test for Flutter. Using bloc_test package you may get rid of unnecessary boilerplate code.
Go ahead and install it like below
flutter pub add -d bloc_test && flutter pub get
To use it, you will start with
The test for BLoC or Cubit is the same. For the should section you should mention emit states. You need to mention the emit() functions.
See how blocTest() takes Cubit and State class. You may also pass Bloc and State class. The parameters inside
<> just like the parameter when you extend
Bloc for your class. When you class extend Bloc class you pass bloc class and state class. Here we are doing the same.
'should emit [CreatingUser, UserCreated] when successful' means first create a user and return the created user. Here CreatingUser and UserCreated are states defined AuthenticationState.
After that for the build parameter when pass an anonymous function. Inside the anonymous function we have to use our usecase. From here on everything else same as a regular TDD test.