#5 - BLoC Testing - Why do you hate testing? It's actually pretty amazing!

  Рет қаралды 32,490

Flutterly

Flutterly

Күн бұрын

Пікірлер: 88
@Flutterly
@Flutterly 4 жыл бұрын
Hello, everyone! The entire course is now live on Udemy too, get it while it's hot --> www.udemy.com/course/bloc-from-zero-to-hero/?referralCode=E689592633984B34DBEF Also I have just managed to finally finish the entire BLoC - From Zero to Hero Complete Course, based on this tutorial series. You can check it out here -> kzbin.info/www/bejne/inmmnJ6HYrtkY5o
@R3d_Devil
@R3d_Devil 4 жыл бұрын
I thought I was familiar with bloc but these tutorial series of yours has taught me a lot. Thank You!
@Flutterly
@Flutterly 4 жыл бұрын
This means a lot to me, mate! Thanks a lot!
@eikeimnetz
@eikeimnetz 2 жыл бұрын
null-safety Update: hi folks, i struggled a bit with the Flutter Update that brings null-safety with it. Here is how it works for me in 04/2022 just to be complete, here are the pub.dev packages I used: *** pubspec.yaml *** dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.4 flutter_bloc: ^8.0.1 bloc_test: ^9.0.3 equatable: ^2.0.3 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^1.0.4 I first made the 'wasIncremented' boolean optional by added an '?' after bool *** counter_state.dart *** part of 'counter_cubit.dart''; class CounterState extends Equatable { int counterValue; bool? wasIncremented; CounterState({ required this.counterValue, this.wasIncremented }); @override List get props => [counterValue, wasIncremented]; } *** counter_cubit.dart *** import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; part 'counter_state.dart'; class CounterCubit extends Cubit { CounterCubit() : super(CounterState(counterValue: 0)); void increment() => emit(CounterState(counterValue: state.counterValue + 1, wasIncremented: true)); void decrement() => emit(CounterState(counterValue: state.counterValue - 1, wasIncremented: false)); } lastly i edited the test file to my needs, the most important things were commented by others here: changing act: (cubit) => cubit.decrement(), to act: (CounterCubit cubit) => cubit.increment(), and changing expect: [CounterState(counterValue: 1,wasIncremented: true)], to expect: () => [CounterState(counterValue: 1,wasIncremented: true)], here you see the endresult for the file *** counter_cubit_test.dart *** import 'package:bloc_test/bloc_test.dart'; import 'package:bloctest/bloc/counter_cubit.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('CounterCubit', (){ late CounterCubit counterCubit; setUp(() { counterCubit = CounterCubit(); }); tearDown((){ counterCubit.close(); }); test('der initiale Status ist CounterState(counterValue:0)', (){ expect(counterCubit.state, CounterState(counterValue: 0)); }); blocTest( 'Das Cubit soll den Status CounterState(counterValue:1,wasIncremented: true) emittieren,' 'wenn die cubit.increment() Funktion aufgerufen wird', build: () => counterCubit, act: (CounterCubit cubit) => cubit.increment(), expect: () => [CounterState(counterValue: 1,wasIncremented: true)], ); blocTest( 'Das Cubit soll den Status CounterState(counterValue:-1,wasIncremented: false) emittieren,' 'wenn die cubit.decrement() Funktion aufgerufen wird', build: () => counterCubit, act: (cubit) => cubit.decrement(), expect: () => [CounterState(counterValue: -1,wasIncremented: false)], ); }); }
@naufalhafizi1044
@naufalhafizi1044 2 жыл бұрын
nice you are the savior man!
@cristiancruz2223
@cristiancruz2223 2 жыл бұрын
it work for me too, thanks men
@poomchantarapornrat5685
@poomchantarapornrat5685 4 жыл бұрын
AMAZING tutorial. Teaching me "why" before "how" makes me know what to expect to get from this topic.
@Flutterly
@Flutterly 4 жыл бұрын
I really appreciate it! You're welcome!
@skypuff
@skypuff Жыл бұрын
This is timeless. I'm now following this series. It's been a couple of years since its release and everything so far still works the same.
@TreyHope
@TreyHope 4 жыл бұрын
Never wrote a bloc test before but now I see how vital it is. Thank you for the solid explanation!
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much! ✨ Glad I could help!
@jayefoucher9586
@jayefoucher9586 Жыл бұрын
I seriously cannot thank you enough for these extremely informative, well explained, and BEAUTIFULLY ANIMATED lectures!!!
@JulianaPassos
@JulianaPassos 4 жыл бұрын
This series is being extremely helpful to my development in BLOC. Your explanation is so clear and direct. Specially about the importance of equatable to trick Dart to compare the instances by value and not by place in memory. I'm happy to be one of the first ones to "discover this channel" and I'm doing each tutorial on the same day that you release them. PRECIOUS material. Thanks so much!
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much for your kind words! Glad I could help!
@AhumadaMauricio
@AhumadaMauricio Жыл бұрын
This series of videos has been so far, very helpful. I want to also point out that, even when you are obviously a non native english speaker, your english is totally understandable even to a non native english speaker like me. Congratulations on your excellent tutorial.
@alisampson6639
@alisampson6639 3 жыл бұрын
After scouting for tutorials on bloc, just the 3 first videos makes me understand how bloc is simple to understand. Best BLOC patter tutorial ever. Thank u so much sir🥰🥰
@shinigami4228
@shinigami4228 Жыл бұрын
As a 2 year Flutter developer, I was always afraid of Bloc because so many tutorials made it look too complicated. That's why I always preferred riverpod and provider, now I can better understand your video series. Thank you buddy
@rounaktadvi4950
@rounaktadvi4950 4 жыл бұрын
Buddy, I appreciate the work you are doing by making a proper series of bloc.I'm getting to learn a lot from your channel.I hope you won't stop making such amazing videos for the aspiring flutter devs.Thank you for this series👍🏻
@Flutterly
@Flutterly 4 жыл бұрын
I won't stop for sure! Thank you for your feedback! ♥
@filippalexandrov1554
@filippalexandrov1554 Жыл бұрын
I normally only write hateful comments, but your tutorials are so amazingly helpful in both theoretical and practical ways, that i had to say Thanks!
@efmuzyka
@efmuzyka 3 жыл бұрын
With new version of bloc_test, this is crucial to add types in method: blocTest()
@OCTsecond
@OCTsecond 4 жыл бұрын
Your videos always clear and easy to understand, help me a lot in the path of learning flutter development!
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much! ✨ Glad to hear that!
@R0cky0
@R0cky0 Жыл бұрын
Great tutorial, Sir. I wonder what theme you are using to display the tree structure within the code as of 3:50? Or any folk knows? Thanks a million!
@somedevstuff5060
@somedevstuff5060 4 жыл бұрын
Great content, looking forward to more videos! Keep it up
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much! Next video will come tomorrow or perhaps on Monday.
@samsonnwokike9897
@samsonnwokike9897 4 жыл бұрын
Awesome videos. I can't wait to learn more from you.
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much, man!
@xutopia
@xutopia Жыл бұрын
I would hit the like on this video twice if I could. Testing is underrated in the industry.
@-RimuruTempest
@-RimuruTempest 4 жыл бұрын
You are the only one to make sense that why we should use equatable ❤️❤️❤️
@Flutterly
@Flutterly 4 жыл бұрын
Thank you so much! ✨
@Dilipkumar-yi1zn
@Dilipkumar-yi1zn Жыл бұрын
Aswome explanation and visual representations. Thank you and best wishes
@kentamammadli8009
@kentamammadli8009 4 жыл бұрын
Amazing tutorial, you are one of the best.
@Flutterly
@Flutterly 4 жыл бұрын
Thank you, man! ✨
@aryanchauhan6671
@aryanchauhan6671 3 жыл бұрын
Awesome video bro. Thanks a lot !
@james-freekp
@james-freekp 3 жыл бұрын
Why the members variables in CounterState automatically change to final itself? around 9:31
@CleisonArenhart
@CleisonArenhart Жыл бұрын
This tutorial is amazing. Thank you so much
@erikaszabo1439
@erikaszabo1439 3 жыл бұрын
I have an error in blocTest( .... act: (cubit) => cubit.increment(), .... ) The method 'increment' can't be unconditionally invoked because the receiver can be 'null'. What's the problem? Couldn't figure out.
@erikaszabo1439
@erikaszabo1439 3 жыл бұрын
nvm. I changed it to: act: (CounterCubit cubit) => cubit.increment() , and now it recognises the increment function
@KuroManX
@KuroManX 2 жыл бұрын
@@erikaszabo1439 you saved my life!
@MSemih-dk6xp
@MSemih-dk6xp 2 жыл бұрын
Thanks man. Appreciated a lot!!
@amikhan7727
@amikhan7727 3 жыл бұрын
Hi, I am facing error 10.07 min according to this video, error: Expected: CounterState: Actual: package:test_api
@paraboliczq
@paraboliczq 4 жыл бұрын
Nice! Thank you once again!
@Flutterly
@Flutterly 4 жыл бұрын
You're welcome!
@swostikgautam5836
@swostikgautam5836 4 жыл бұрын
bro it would be vey helpful if you make tutorials like 1. Login with tokens and parse data from public api using bloc 2. How to use new firebase update on authentication and retrieving data from firebase using boc 3. And packages like freezed, get_it etc etc... you will have my life long gratitude if you get time to make these videos anyway thanks for all explanation bro,,,I hope your channel blows...no one have made videos like this
@Flutterly
@Flutterly 4 жыл бұрын
Sure, will cover everything in future tutorials!
@swostikgautam5836
@swostikgautam5836 4 жыл бұрын
@@Flutterly thank you bro...looking forward your new videos
@charlesarieschang4317
@charlesarieschang4317 8 ай бұрын
what are your vscode extensions for the broken lines to see nesting?
@davidagyakwa288
@davidagyakwa288 2 жыл бұрын
can there be a longer version or an updated version of this video for bloc
@juansanmiguel
@juansanmiguel 3 жыл бұрын
Hi WCKD! I am loving this course but I am having an issue with blocTest. I am getting this error when I try to test the increment and decrement functions. The argument type 'List' can't be assigned to the parameter type 'dynamic Function()'. Maybe you can help me?
@louis-mariemmd3918
@louis-mariemmd3918 3 жыл бұрын
You need to add () => like that : expect: () => [CounterState(counterValue: 1,wasIncremented: true)],
@kawsarmoqadsa5990
@kawsarmoqadsa5990 Жыл бұрын
omg!! thank you, i have benn looking everywhere trying to find the solution to the error. @@louis-mariemmd3918
@quicksketch1617
@quicksketch1617 4 жыл бұрын
There is a way to compare without equatable? Always has to use equatable to test?
@Flutterly
@Flutterly 4 жыл бұрын
Check out my latest tutorial #10. You'll find out
@Imheretohelpnhavefun
@Imheretohelpnhavefun 3 жыл бұрын
Is it safe to just use Equatable on stuff like that? Isn't there a reason for the standard equal signal to compare pointers instead of instance values? Great series, by the way, I'm learning a lot
@Flutterly
@Flutterly 3 жыл бұрын
Yes, of course it's safe. Equatable's only purpose is to make Dart compare objects by value instead of pointers.
@fr1day1700
@fr1day1700 3 жыл бұрын
So im trying to follow this with the new version of test and equatable .... its not working, null safety stuff is throwing me off. Is this not valid anymore for 2021?
@EmilianoKalafatic
@EmilianoKalafatic 3 жыл бұрын
I don't understand what's happening but flutter don't recognize the import from equatable, test and bloc_test
@keithbacalso9433
@keithbacalso9433 3 жыл бұрын
I still do not understand why we still need to test even tho the code is now working.. I mean do we have to test everytime there is a variable it may be String, int, List, AnimationController, blabla controller, and all other variables to mention.... When do we test??? I am so confuse.... do we test only if there are events or actions like increment and decrement?? when?
@rohitsrao
@rohitsrao 2 жыл бұрын
You build a test suite to give you confidence later that when you implemented a new feature or refactored your code, you haven't accidentally broken something elsewhere.
@raul286162
@raul286162 4 жыл бұрын
I got it, the importantance now. But don't understand yet if i need really make a mirror folder of my lib, I mean if I have pages, blocs, repositores, all together making a total of 65 dart. archives, do I must create 65 test archives?
@Kolano666
@Kolano666 4 жыл бұрын
What he did by separating each test to corresponding folder and placing tests inside is just a suggestion of one possible sollution to test management. You can align them like you want inside test folder as long as it makes sense and is easly readable. The very important thing about tests is that you have to know the measure and not test literally everything because some things are too shallow to test them. Somone can say that its best to have everything covered but in reality you not gonna test every widget if its opening after clicking every possible button inside app but rather important businnes logic of application f.e will app react propertly to various responses from REST API etc. If you are learning test everything and after time you will recognize what is worth testing.
@raul286162
@raul286162 4 жыл бұрын
@@Kolano666 thank you very much, I really glad you made this summary since I'm new in testing i need to have an overview.
@Flutterly
@Flutterly 4 жыл бұрын
Thank you for this extremely helpful reply!
@حسينش-ك7ج
@حسينش-ك7ج 3 жыл бұрын
man you are the best
@Flutterly
@Flutterly 3 жыл бұрын
Thank you, ma man!
@lauchiebeans
@lauchiebeans 4 жыл бұрын
I see you hearted my comment on your previous video, does that mean what I think it does and we might see an android video on the main channel o_O? Or am I just speculating haha.
@Flutterly
@Flutterly 4 жыл бұрын
Unfortunately no, I don't have time for that anymore, mate. Sorry to disappoint you. Maybe in the future 🔮
@lauchiebeans
@lauchiebeans 4 жыл бұрын
@@Flutterly A man can dream.
@abanahmed4683
@abanahmed4683 4 жыл бұрын
Man you bloc my mind ❤️! Lol
@Flutterly
@Flutterly 4 жыл бұрын
😂 😂 Haha, I'm bloced
@abanahmed4683
@abanahmed4683 4 жыл бұрын
😂❤️
@Add0w
@Add0w 4 жыл бұрын
Every nice channel I discover has this problem they don't continue what they started.
@Flutterly
@Flutterly 4 жыл бұрын
What do you mean? What didn't I continue?
@Flutterly
@Flutterly 4 жыл бұрын
If you're referring to the fact that I didn't post in a long time, I was too busy talking an exam and didn't have the time to do the next video. It takes almost a week straight to do a video like this.
@Add0w
@Add0w 4 жыл бұрын
@@Flutterly sorry I didn't mean it to you personally but there are other chanels started explaining flutter very nicely and was enjoying watching and liking their videos but ended up a months without videos.
@Flutterly
@Flutterly 4 жыл бұрын
It won't be true in my case. It was just that I have other exams to sort out before. Sorry for the inconvenience.
@Add0w
@Add0w 4 жыл бұрын
@@Flutterly sorry for that comment and thank you.
@FLUTTER_HUB
@FLUTTER_HUB 10 ай бұрын
any one here from 2024?
@Hasan-po6ud
@Hasan-po6ud 2 жыл бұрын
Thanks
@dev_shaiful
@dev_shaiful Жыл бұрын
Super
@yaqub3567
@yaqub3567 2 жыл бұрын
This way of blocTest isn't working any more
@samelobinna101
@samelobinna101 Жыл бұрын
this uncalled for anyway,
@delmontee
@delmontee 11 ай бұрын
The test section using the code provided no longer works, readDown and the test functions have errors :(
Flutter Testing For Beginners - The Ultimate Guide
13:05
Robert Brunhage
Рет қаралды 60 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Flutter Unit Testing Explained | Testing Series Codepur.dev
21:44
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 226 М.
Widget Testing with Flutter
8:16
Tadas Petra
Рет қаралды 30 М.
Top 30 Flutter Tips and Tricks
6:50
Flutter Mapp
Рет қаралды 580 М.
Flutter Testing Guide for Beginners - Part 1: Unit Tests & Setup
1:00:28
Flutter Bloc & Cubit Tutorial
47:58
Reso Coder
Рет қаралды 122 М.
Learn Flutter Life Cycle In 10 Minutes
10:02
Robert Brunhage
Рет қаралды 76 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН