No video

Flutter TDD Clean Architecture Course [2] - Entities & Use Cases

  Рет қаралды 137,176

Reso Coder

Reso Coder

Күн бұрын

📗 Learn from the written tutorial 👇👇
resocoder.com/...
👨‍💻 Do you write good code? Find out now!
resocoder.com/...
In the first part, you learned the core concepts of clean architecture as it pertains to Flutter. We also created a bunch of empty folders for the presentation, domain and data layers inside the Number Trivia App we're building. Now it's time to start filling those empty folders with code, using TDD, of course.
Whenever you are building an app with a UI, you should design the UI and UX first. I've done this homework for you and the app was showcased in the previous part.
The actual coding process will happen from the inner, most stable layers of the architecture outwards. This means we'll first implement the domain layer starting with the Entity.
Go to my website for more information, code examples, and articles:
● resocoder.com
Follow me on social media:
● / resocoder
● / resocoder
● / resocoder

Пікірлер: 267
@ryftus5004
@ryftus5004 4 жыл бұрын
TAKE NOTE! For people that just started now, the latest equatable requires you to use props rather than super constructors. So, Rather than this:- class NumberTrivia extends Equatable { final String text; final int number; NumberTrivia({ @required this.number, @required this.text }) : super([number,text]); } //WRONG Do this:- class NumberTrivia extends Equatable { final String text; final int number; NumberTrivia({ @required this.number, @required this.text }); @override List get props => [text, number]; } Peace!
@mostafaabozaina4146
@mostafaabozaina4146 3 жыл бұрын
Not wrong it's just old version than the current available one
@ahmedmustahid4936
@ahmedmustahid4936 2 жыл бұрын
Thanks a lot
@fikrihaikal1353
@fikrihaikal1353 2 жыл бұрын
Thank you so much bro, you're a live saver
@anassa6737
@anassa6737 Жыл бұрын
for failures on core/error how i can solve the problem when i put the the lsit on super the respone to me no argmunts expection
@urosteofilovic2394
@urosteofilovic2394 Жыл бұрын
@@anassa6737 I have same problem, hadn't found the solution yet
@muikrizalit6449
@muikrizalit6449 4 жыл бұрын
7:30 equatable: ^1.0.1 Use @override List get props => [text, number]; instead of : super([text, number])
@psybitcoin
@psybitcoin 4 жыл бұрын
and in abstract class Failure?
@virenkhatri1932
@virenkhatri1932 4 жыл бұрын
Thank You, helped a lot! also, what about abstract class Failure?
@utarnburanasaksri8241
@utarnburanasaksri8241 4 жыл бұрын
@@virenkhatri1932 No need to override the props in abstract class. Instead, you will need to override props in the implemented class.
@David-rc8nm
@David-rc8nm 5 жыл бұрын
I'm coding for years as a hobby but you know.. never did anything in any professional manner but I always wanted to get better... and I have to say that until now it was difficult for me to comprehend the process of TDD and how to design a software in a professional or efficient way, or for the least part how to keep solid and clean code. Just from watching this video several Lego blocks connected in my head so thank you so much! And I cant wait to go through this course !!
@ResoCoder
@ResoCoder 5 жыл бұрын
I'm glad those Lego BLoCs 😉 fell in place for you!
@matiasgomez9416
@matiasgomez9416 5 жыл бұрын
domain/entities/number_trivia > 3:50 --> JSON core/error/failures > 12:30 --> abstract class domain/entities/number_trivia_repository > 15:50 --> abstract class test > 20:30 test/.../domain/usecases/get_concrete_number_trivia > 22:30 --> mockito domain/usecases/get_concrete_number_trivia > 26:20 run program > 36:50
@h3w45
@h3w45 Жыл бұрын
thanks
@scottb2284
@scottb2284 5 жыл бұрын
I really appreciate this tutorial so far because it's language agnostic. My struggle with coding has been less about understanding a particular language/dialect (they all say/do the same things, just in slightly different ways) and more about knowing how to structure a code base, where to put the files, how those files relate to each other, what to name them, when to write them (and why). This course is an architectural blueprint I can follow in any project in any stack. That way I'm not reinventing the wheel for every project I do and I'll get a lot of practice repeating these patterns, which means that over time I'll get faster at creating new projects. Thank you!
@ResoCoder
@ResoCoder 5 жыл бұрын
That was my goal in creating this course. Thanks for learning here!
@clown7094
@clown7094 4 жыл бұрын
I feel the same bro
@isurujn
@isurujn 2 жыл бұрын
Hear hear. After almost 10 years of coding, I still struggle with this. This video series is a gold mine. I'd pay for it if it was behind a paywall.
@bascelik91
@bascelik91 4 жыл бұрын
It took me 5 iterations and 2 months to understand what you are doing :) thanks Matt !
@luizmoraes4371
@luizmoraes4371 3 жыл бұрын
Pls update the course to Null Safety :)
@anassa6737
@anassa6737 Жыл бұрын
did you solve it
@vayshnavisivarajah485
@vayshnavisivarajah485 Жыл бұрын
Did someone find a solution please ?
@cnawico
@cnawico 3 жыл бұрын
We need an update for Null-Safety, at least just a written one for the tests part. The production code is easy enough to adapt but I find it very difficult to adapt the tests. Mockito has documented solutions to the issue but given this is my very first foray into TDD, all I read is mumbo-jumbo... Being specific, the IDE shrieks at me when using "any" as an argument matcher. I have no idea how to make this pass null-safety.
@giovanniitaliano4725
@giovanniitaliano4725 2 жыл бұрын
Have you solved this issue? I'm facing the same, thanks
@mbabuglia
@mbabuglia 2 жыл бұрын
mockito doesn't play well with null-safety. You should switch to mocktail. The syntax is mostly the same, the migration is relatively easy.
@legardemontcho6739
@legardemontcho6739 2 жыл бұрын
I had the same problem. In writing the test every time you give a different number of tnumber, the test will not be conclusive. I think "any" was just an example but if you want the test to work, you have to give tNumber there.
@anthonyjosuejarabustamante5314
@anthonyjosuejarabustamante5314 2 жыл бұрын
@@mbabuglia Using mocktail instead and it's working now. Thanks!!
@anthonyjosuejarabustamante5314
@anthonyjosuejarabustamante5314 2 жыл бұрын
test( 'shoud get trivia for the number from the repository', () async { //arrange when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(any())) .thenAnswer((_) async => const Right(tNumberTrivia)); //act final result = await usecase.execute(number: tNumber); //assert expect(result, const Right(tNumberTrivia)); verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber)); verifyNoMoreInteractions(mockNumberTriviaRepository); }, );
@alfonsoisraelosorioavilez7
@alfonsoisraelosorioavilez7 5 жыл бұрын
Excellent video course, the form of how you explain the things and the way of how the video was created is awesome. Thank you very much for share your knowledge with us, after watch this video I think that this is the architecture that I go to implement in my future projects, TDD + Clean Architecture + Bloc, it is simply a jewel.
@fridakalos
@fridakalos 5 жыл бұрын
The Best flutter course Ive found, just keep posting, you've got followers. Keep waiting for your videos.
@fredericowebmaster
@fredericowebmaster 5 жыл бұрын
Your videos are amazing. Your clean language and dedication to teaching are very impressive to me. Thank you for sharing your knowledge with us.
@yanuaryusufadika7045
@yanuaryusufadika7045 4 жыл бұрын
This is what I looking for. Somehow senior programmer always told to me that we need to do TDD process when we code clean architecture. Unfortunately, I don't understand what the TDD is . In my desperate situation, I tried to find out TDD on youtube. And I found it, very good dude, love your video 👍👍
@06dsyaniketnemade52
@06dsyaniketnemade52 5 ай бұрын
Your teaching directly hit to heart bcz you make explanation as simple as possible .... And its Feels good i appreciate it!💯
@bytebrunoOld
@bytebrunoOld 2 жыл бұрын
2022 - What I did to work => // Dependencies - pubspec.yaml: dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 get_it: ^7.2.0 flutter_bloc: ^8.0.1 equatable: ^2.0.3 dartz: ^0.10.1 internet_connection_checker: ^0.0.1+4 http: ^0.13.4 shared_preferences: ^2.0.15 dev_dependencies: flutter_test: sdk: flutter mocktail: ^0.3.0 ------------------------------------------------- // NumberTrivia entity (override instead of super constructor) @override List get props => [text, number]; -------------------------------------------------- // Test file with mocktail class MockNumberTriviaRepository extends Mock implements NumberTriviaRepository {} void main() { late MockNumberTriviaRepository mockNumberTriviaRepository; late GetConcreteNumberTrivia usecase; setUp(() { mockNumberTriviaRepository = MockNumberTriviaRepository(); usecase = GetConcreteNumberTrivia(mockNumberTriviaRepository); }); const tNumber = 1; const tNumberTrivia = NumberTrivia(text: 'test', number: tNumber); test('should get trivia for the number from the repository', () async { // arrange when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(any())) .thenAnswer((_) async => const Right(tNumberTrivia)); // act final result = await usecase.execute(number: tNumber); // assert expect(result, const Right(tNumberTrivia)); verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber)); verifyNoMoreInteractions(mockNumberTriviaRepository); }); }
@sagarkrishnabose8612
@sagarkrishnabose8612 2 жыл бұрын
Thanks, man! Saved a ton of time for me :)
@bytebrunoOld
@bytebrunoOld 2 жыл бұрын
@@sagarkrishnabose8612 No worries! I'm glad to hear that, it was a pain for me haha. :) edit: I just updated the pubspec here. I changed the connectivity_plus dependency to internet_connection_checker due to null safety issues with the connectivity packages.
@marlonsubuyu2012
@marlonsubuyu2012 Жыл бұрын
Thanks man, it worked :)
@matheussoaressilveira8408
@matheussoaressilveira8408 5 жыл бұрын
Thank you for this course! I'll base over this arquitecture for some future personal projects using Flutter.
@programan6391
@programan6391 4 жыл бұрын
This guy deserves be (very well) paid by Google.
@dc5
@dc5 4 жыл бұрын
This is great, thank you for such an awesome explanation. Just two things I'm struggling with, 1 - Do you create all that folder structure for each "feature" in your app, both in the source and test folders? 2 - Do you create separate classes/files for every single method (what you call use case) of every feature? Loving the way you are explaining TDD with Clean Architecture for Flutter, but can't wrap my head about how many files and folders are required for creating just one screen with only two api calls. I'm probably missing something. Thanks a lot Reso!
@ResoCoder
@ResoCoder 4 жыл бұрын
I'm glad you find this valuable! The answer is yes and no at the same time. That is, you should create separate folders for features and files for use cases if you're strictly following Clean Architecture. However, if you feel that "perfect is the enemy of the good", you can also just scratch the use cases and put their logic into a BLoC. The bottom line is - it's all malleable as long as it's maintainable 😉
@dc5
@dc5 4 жыл бұрын
@@ResoCoder Thanks a lot for the quick response, that's true, it can all be adopted to suit particular needs as long as it's maintainable, that's the key. I'm glad you mentioned in the first video that by following the clean architecture it doesn't matter which state management you use, I'm leaning more toward Provider, would love to see an explanation from your point of view on how to use Provider with Clean Architecture. Again, thanks for sharing! Awesome videos!
@legardemontcho6739
@legardemontcho6739 2 жыл бұрын
@@dc5 The biggest challenge would be to get the same result by changing BloC to Provider. I changed equatable to freezed and believe me I learned some new tricks about freezed while trying to fix the bugs. I also changed NumberTrivia to Order, it was still fadcinating. I'm just looking forward to the next step.
@ShadowInfest
@ShadowInfest 5 жыл бұрын
Amazing tutorials, not just beginner stuff and always the same, everything is well structure and you deeply thought about what to tell and show! Relaxing voice, perfect speed and Linux haha. Keep up that good work!!
@pashute12
@pashute12 5 жыл бұрын
Thanks!! Two small remarks: 1. IMHO, a Failure abstract class should be called failure.dart not failures.dart. The folder holding it, which takes care of errors should be called errors and not error... 2. it would be good if you could give a short example of what kind of logic would be typically found in an entity. (say a line or two of code commented out, or quickly written and erased)
@abderrahmansettani9843
@abderrahmansettani9843 5 жыл бұрын
Keep going man, this is very well done, beautify explained.
@Flutterdev6391
@Flutterdev6391 3 жыл бұрын
Thanks bro it's little bit difflicult for beginning when you start learning TDD but I m sure at the end of this tutorials I will get atleast 60-70%
@vedantkulkarni9098
@vedantkulkarni9098 2 жыл бұрын
This is the best and most advanced flutter tutorial so far, keep going brother !
@ikram-hasan
@ikram-hasan 3 жыл бұрын
This is the snippet for aaa test: "Arrange Act Assert test": { "prefix": "aaatest", "body": [ "test(", " 'should ${1}',", " () async {", " // arrange", "", " // act", "", " // assert", " },", ");" ], "description": "Arrange Act Assert test" },
@carlosfau4492
@carlosfau4492 3 ай бұрын
Very interesting presentation of an architecture. I have a question for you. In functional programming, you usually have an Either and a Try defined as Try = Either. A Future can be seen as an asynchronous version of Try. Why don't you use the Future error response to handle errors and instead adds an additional layer of wrapping the error inside an Either inside the Future? Is just to differentiate "Business" errors from "infrastructure" errors?
@mdikcinar
@mdikcinar Жыл бұрын
20:00 - Currenty if you right click the file that you want to write test and select go to test option, it will ask do you want create that file with same folder structure. Easy peasy :)
@husseinqabalan775
@husseinqabalan775 2 жыл бұрын
update ------------- for you test to work: 1.remove this line: class MockNumberTriviaRepository extends Mock implements NumberTriviaRepository {} 2.and annotate Main method with this: @GenerateMocks([NumberTriviaRepository]), PS. you need to import mockito/annotations.dart 3. go to terminal and run this command: flutter pub run build_runner build 4. import the new generated class. (MockNumberTriviaRepository) 5. done.
@thanhvietnguyen998
@thanhvietnguyen998 2 жыл бұрын
Thank you very much.
@dedeandres455
@dedeandres455 2 жыл бұрын
thank you bro, really helpful
@ochornmapromise257
@ochornmapromise257 2 жыл бұрын
Could not find package "build_runner". Did you forget to add a dependency? The error am getting
@krishnateja296
@krishnateja296 2 жыл бұрын
@@ochornmapromise257 run this in the project terminal -> flutter pub add build_runner
@FabrizioCacicia
@FabrizioCacicia 5 жыл бұрын
Can't wait for the next part!
@johnjackson4082
@johnjackson4082 3 жыл бұрын
At around 8 minutes you suggest writing tests on the entity if there is some logic in it. I think uncle bob suggests only testing the boundaries of the use case. The application only touches boundaries, not the entities. I don't think it is in his book but he talked about it at a conference when he talked about the originator of use case driven design.
@hexdump8590
@hexdump8590 4 жыл бұрын
I don't like to have dependencies in my code that I don't need. So, instead of dartz, why not just use a generic class with just a boolean to flag error/success and a member with the data (NumberTrivia) if everything is ok? Something like: class Result { bool success, T data }. By the way, awesome vids!
@saadghazal9743
@saadghazal9743 Жыл бұрын
type 'Null' is not a subtype of type 'Future' when i run the test
@mirxtremapps
@mirxtremapps 2 жыл бұрын
i recommend this vs-code extension "Flutter & Dart Utilities", it let you create quickly equatable, mocks classes an more
@SEOTADEO
@SEOTADEO 2 жыл бұрын
Thanks a lot for this video! Especially getting to know the Either type from dartz was helpful.
@mugume
@mugume Жыл бұрын
Dude, you are the best at what you do. I love the quality of your tutorials, excellence at play. Thank you 🙏🏾
@saadghazal9743
@saadghazal9743 Жыл бұрын
hi i faced a problem with the any key word i just need to know how to fix it
@mugume
@mugume Жыл бұрын
@@saadghazal9743 not sure buddy, but you could ask the author on the channel
@saadghazal9743
@saadghazal9743 Жыл бұрын
@@mugume i fixed it 🔥🔥🔥
@user-xl2je5ul8t
@user-xl2je5ul8t Жыл бұрын
@@saadghazal9743 how
@alisampson6639
@alisampson6639 Жыл бұрын
@@saadghazal9743 How did you fix it?
@sametsahin10
@sametsahin10 4 жыл бұрын
For those who are using Android Studio or IntelliJ as development environment, refer to this medium post for running tests. Select get_concrete_number_trivia.test as file instead of widget_test as it's mentioned in the post. medium.com/flutterpub/writing-and-running-widget-tests-from-android-studio-d63b9fea21c5
@RobertWildling
@RobertWildling 5 жыл бұрын
To the down-voters: At least be so fair and leave a constructive comment, so we know about the different points of views!
@andreykaok9497
@andreykaok9497 5 жыл бұрын
I guess that down-voters are conservative xCode and Android SDK developers which understand that Flutter is really coming to win. ;)
@wickedgummybear3104
@wickedgummybear3104 4 жыл бұрын
@@andreykaok9497 Doesnt even have to be that, might be that the program just is'nt running properly.
@illiamaksymenko804
@illiamaksymenko804 4 жыл бұрын
only 7 for now, not so much..
@RSPSify
@RSPSify 3 жыл бұрын
@@andreykaok9497 Honestly you are probably right. Between Jetpack Compose and Kotlin, I realized the only way out of "Hell" is platform independence. But many are just bitter over it, they see flutter as another change.
@onwuasoanyageorge5364
@onwuasoanyageorge5364 3 жыл бұрын
I long convinced myself that down-voters are bots. Can't tell me nothing else!
@westiti6650
@westiti6650 4 жыл бұрын
I don't think async/await are necessary for a function definition that returns a Future : Future execute({@required int number}) { return repository.getConcreteNumberTrivia(number); } .But only when the Future is consumed such as: final result = await execute(number: Number);
@loicngou9592
@loicngou9592 5 жыл бұрын
Even your blog is well written , mamamyah..well done
@baby45058
@baby45058 4 жыл бұрын
hi i meet problem with Failure class Failure([List properties = const[]]) : super(properties); ->too many positional arguments i can not run test and i don't know which way i wrong
@bmkgokong668
@bmkgokong668 4 жыл бұрын
remove the super(properties) at the end, same with the entities file - the documentation for Equatable is available on the dart-package page
@afriendlyfellow
@afriendlyfellow 7 ай бұрын
in the test file, the variables usecase and mockNumberTriviaRepository should be marked as `late`, or else you will get compile errors like "The non-nullable local variable 'usecase' must be assigned before it can be used."
@dc5
@dc5 4 жыл бұрын
Hi Reso, would be great to have some example of Update/Delete to see how you implement unit test for those. Thx
@legardemontcho6739
@legardemontcho6739 2 жыл бұрын
1) Thank you for the introduction to testing, it helps the beginner developer to improve his thinking. I followed your introduction and to understand it well I adapted it by changing equatable to freezed (Most recommended for equal value on pub). 2) I used an e-comerce order entity instead of triviaNumber. But I'm a little confused about how to write order test that contains customer?
@06dsyaniketnemade52
@06dsyaniketnemade52 5 ай бұрын
Big fan bro...big fan 🥺❤️
@vladimirmbassi
@vladimirmbassi 5 жыл бұрын
Awesome video, can't wait for the next parts
@virenkhatri1932
@virenkhatri1932 4 жыл бұрын
I wish there was a LOVE reaction on youtube. I don't just like it, i love it
@BelgianDaSeeD
@BelgianDaSeeD 5 жыл бұрын
Many thanks for your super clean tutorials ! Love them !
@msayeed78
@msayeed78 4 жыл бұрын
Excellent. I never tested apps like this so it is new and little difficult to understand. I will search for tutorial on test.
@uDropper
@uDropper 7 ай бұрын
I want to be a teacher and if my classes happen to have the same quality as yours, I will be very happy, you could make a tutorial about that.
@VS.VishalSharma
@VS.VishalSharma 4 жыл бұрын
I can't understand this code in failure Failure([List properties = const []]) : super(properties); .what does it do exactly??
@thedevkim2934
@thedevkim2934 3 жыл бұрын
Hi. can you do a refactor for the latest version of Dart ? Im having so many errors
@conmeu6364
@conmeu6364 Жыл бұрын
for people who got "the non-nullable variable "..." must be initialized" error in the test file, u just need to add "?" at the declaration: void main() { GetConcreteNumberTrivia? usecase; MockNumberTriviaRepository? mockNumberTriviaRepository; setUp(() { mockNumberTriviaRepository = MockNumberTriviaRepository(); usecase = GetConcreteNumberTrivia(mockNumberTriviaRepository!); }) ; final tNumber = 1; final tNumberTrivia = NumberTrivial(text: 'test', number: 1); test('should get trivia from the number from the repository', () async { when(mockNumberTriviaRepository?.getRandomNumberTrivia(any)) .thenAnswer((_) async => Right(tNumberTrivia)); final result = await usecase?.execute(number: 20); expect(result, Right(tNumberTrivia)); verify(mockNumberTriviaRepository?.getConcreteNumberTrivia(tNumber)); verifyNoMoreInteractions(mockNumberTriviaRepository); }); }
@lugardjulien5326
@lugardjulien5326 2 жыл бұрын
For generating API fetching data I highly recommend retrofit package , also don't bother yourself writing the data class on your own , generate them with freeze package .
@anassa6737
@anassa6737 Жыл бұрын
how did you take off the null problem on test part
@gersongallo6892
@gersongallo6892 5 жыл бұрын
I just found a gem, thanks man!
@kecap_maniis
@kecap_maniis Жыл бұрын
im testing an object class instead of text and int. but its always return null. i did exactly what the video tells me....
@AhmedAlaa-qs3ew
@AhmedAlaa-qs3ew 3 жыл бұрын
type 'Null' is not a subtype of type 'Future' when running test code Any Help
@gaweringo
@gaweringo 2 жыл бұрын
This video is from before when dart had null-safety. To fix this I switched from mockito to mocktail. It's almost a drop in replacement. when() needs to be turned into when(() => ) and any turns into any() but then it works for me.
@ibensalcie
@ibensalcie Жыл бұрын
How I solved it? 0. Use late while initialising the Repository mocks. late GetConcreteNumberTrivia usecase; late MockNumberTriviaRepository mockNumberTriviaRepository; 1. Changed mockito to mocktain : ^0.3.0 (Currently) 2. //Arrange will appear like so. when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(any()),).thenAnswer((_) async => Right(tNumberTrivia)); 3. //act final result = await usecase.excecute(number: tNumber); 4. //assert expect(result, Right(tNumberTrivia)); verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber),); verifyNoMoreInteractions(mockNumberTriviaRepository); Test passes correctly.
@eduardovinicius6047
@eduardovinicius6047 Жыл бұрын
If you're having "type 'Null' is not a subtype of type..." paste @GenerateNiceMocks([MockSpec()]) a line above the main() instead of declaring the class yourself, then use "dart run build_runner build" (you must have build_runner added to your project, which you can do by using "dart pub add build_runner --dev"). When the mock is created just import it.
@SpellOdyssey
@SpellOdyssey 3 жыл бұрын
I really like your effort thank you so much, but I get some errors that I can deal with like the name of the class NumberTrivia needs to be overridden and the super [ Too many positional arguments: 0 expected, but 2 found. Try removing the extra ] line doesn't work for me, can anyone help me with this thank you again man I really appreciate your work and your detailed information on FLUTTER
@westiti6650
@westiti6650 3 жыл бұрын
In the execute() function, you do not need to use async/await because the function already returns a Future.
@ayushpawar9312
@ayushpawar9312 2 жыл бұрын
If anyone is figuring out on how to get rid of the TypeError(type 'Null' is not a subtype of type 'Future') error, 1) Add build_runner package under dev dependencies in pubspec.yaml file. 2) Copy Paste this code 3) in the terminal, run this command: flutter pub run build_runner build // new imports import 'package:dartz/dartz.dart'; import 'package:flutter_num_trivia/features/numbertrivia/domain/entitites/number_trivia.dart'; import 'package:flutter_num_trivia/features/numbertrivia/domain/repositories/number_trivia_repository.dart'; import 'package:flutter_num_trivia/features/numbertrivia/domain/usecases/get_concrete_number_trivia.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'get_concrete_number_trivia_test.mocks.dart'; // new annotation @GenerateMocks([NumberTriviaRepository]) void main() { // initialization outside of setUp final tNumber = 1; final tNumberTrivia = NumberTrivia(number: 1, text: 'test'); final mockNumberTriviaRepository = MockNumberTriviaRepository(); final usecase = GetConcreteNumberTrivia(mockNumberTriviaRepository); test( 'should get trivia for the number from the repository', () async { //arrange when(mockNumberTriviaRepository.getConcreteNumberTrivia(1)) .thenAnswer((_) async => Right(tNumberTrivia)); // act final result = await usecase.execute(number: tNumber); // assert expect(result, Right(tNumberTrivia)); verify(mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber)); verifyNoMoreInteractions(mockNumberTriviaRepository); }, ); }
@enriquemarin8842
@enriquemarin8842 2 жыл бұрын
Thank you very much, bro
@simileoluwaaluko7582
@simileoluwaaluko7582 2 жыл бұрын
Works to fix the error type `` 'Null' is not a subtype of type 'Future ``. Thanks mate
@ibensalcie
@ibensalcie Жыл бұрын
How I solved it? 0. Use late while initialising the Repository mocks. late GetConcreteNumberTrivia usecase; late MockNumberTriviaRepository mockNumberTriviaRepository; 1. Changed mockito to mocktain : ^0.3.0 (Currently) 2. //Arrange will appear like so. when(() => mockNumberTriviaRepository.getConcreteNumberTrivia(any()),).thenAnswer((_) async => Right(tNumberTrivia)); 3. //act final result = await usecase.excecute(number: tNumber); 4. //assert expect(result, Right(tNumberTrivia)); verify(() => mockNumberTriviaRepository.getConcreteNumberTrivia(tNumber),); verifyNoMoreInteractions(mockNumberTriviaRepository); Test passes correctly.
@ajinzrathod
@ajinzrathod 2 жыл бұрын
32:07 The non-nullable local variable 'mockNumberTriviaRepository' must be assigned before it can be used.
@TheGT240
@TheGT240 2 жыл бұрын
Just use lazy initilization - with keyword 'late': void main() { late GetConcreteNumberTrivia usecase; late MockNumberTriviaRepository mockNumberTriviaRepository;
@juniormalcom6603
@juniormalcom6603 Жыл бұрын
@@TheGT240 thanks
@TakinProfit
@TakinProfit 4 жыл бұрын
I really prefer to package by feature, but within each feature folder, I keep things hexagonal. This just makes a lot more sense to me than layering.
@mohsenuss91
@mohsenuss91 3 жыл бұрын
Thank you for this great tutorial !!! Would you please make another one for more real use cases such us SIGNUP/LOGIN using this TDD method?
@user-eh5wo8re3d
@user-eh5wo8re3d 4 жыл бұрын
Using failures instead of the provided catchError feels very much like an anti-pattern to me. What is the benefit of returning failures and having to handle them further up instead of just handling exceptions?
@panosgr7228
@panosgr7228 4 жыл бұрын
Your code will be much more organized if you can catch errors as soon as possible (ie in the Repository) and if you return Failures you won't need to worry about exceptions throughout all the rest of your code. You can have a control-flow depending on whether the result was a Failure or not anywhere in the Domain and pass the needed data to show in the Presenter. If you need to add a new type of Failure you can simply handle it in the Repository and you wouldn't need to search throughout the entire codebase for the line which is catching the exception/failure.
@habibbellia2607
@habibbellia2607 5 жыл бұрын
Thank you I am interesting for this architecture 👍👍👍
@hellofolks5606
@hellofolks5606 4 жыл бұрын
Hey Reso, I'm a bit confused by something. The (_) in .thenAnswer((_) async => Right(tNumberTrivia)) is an argument, correct? When I hover over it, it merely says it is an Invocation, and I can't find any documentation regarding this. Also, if _ is an argument, what is its value in this case? Is it what is returned by getConcreteNumberTrivia(any)? Or is it something returned from when? Thanks!
@hellofolks5606
@hellofolks5606 4 жыл бұрын
Also, why do we need to declare async after .thenAnswer? Isn't async used to indicate to flutter that we will be awaiting something?
@dharmikthakkar3642
@dharmikthakkar3642 3 жыл бұрын
Very rare and useful series. Very Nicely explained...I also have a question. If I got 2 features then do I have to create all folders again for 2 different features? Like do i have to create 2 data folder, domain and presentation folders?
@natdiv9
@natdiv9 Жыл бұрын
Thank you for your video which contains clear explanations I still have a question about the entities, since with this architecture, each feature contains three main folders representing the 3 layers, domain, data and data source. What if an entity is used in two different features? Do we write it twice?
@saadghazal9743
@saadghazal9743 Жыл бұрын
hi guys this tutorial is powerful and it's really great thank you but i'm having an error in the any key word i set the int parameter to int? to make it pass but that's not enough any help
@trungbui7518
@trungbui7518 Жыл бұрын
i have the same problem. Help me
@user-tf4cd2rw3t
@user-tf4cd2rw3t 11 ай бұрын
you probably need any() instead of any
@programmingnight
@programmingnight 3 жыл бұрын
Can u do Tdd clean new course in 2021 with flutter 2? this Architecture is the best I ever found for flutter. Thank You.
@user-gc6fu9fd5u
@user-gc6fu9fd5u Ай бұрын
what was the dart version used here?
@nautiluscove4730
@nautiluscove4730 4 жыл бұрын
Not sure why, but lately all programming videos are way better x 1.5 speed :)
@jeffreymercado1659
@jeffreymercado1659 8 ай бұрын
You made me laugh with the 'Spaguetti code ca´nt be tested'
@mateuspedroso6547
@mateuspedroso6547 2 жыл бұрын
It's so good this video! thks!!! If u can make an similar tut for the nem Flutter version it;s going to be great!!! thks again!!
@YomenChannel
@YomenChannel 5 жыл бұрын
Why do you prefer relative imports?
@vjmathew6962
@vjmathew6962 4 жыл бұрын
the problem i encountered was when i want to change the package name, i had to do the change in every imports
@AliAhmad-fx3dj
@AliAhmad-fx3dj Жыл бұрын
Really need the course with Null Safety.
@anassa6737
@anassa6737 Жыл бұрын
class ServerFailure extends Failure { @override // TODO: implement props List get props => throw UnimplementedError(); } can you solver ot plz
@VandersonRodriguessilva
@VandersonRodriguessilva 4 жыл бұрын
Many thanks for that. Well done.
@anassa6737
@anassa6737 4 ай бұрын
Bad state: No method stub was called from within `when()`. Was a real method called, or perhaps an extension method?
@flujan987
@flujan987 3 жыл бұрын
amazing, very good job, thanks for sharing
@MaximoPower2024
@MaximoPower2024 3 жыл бұрын
Please give some tips for Null Safety. Libraries equatable, connectivivy and shared_preferences are labelled as legacy.
@amanpalariya
@amanpalariya 4 жыл бұрын
Why are we creating classes for *use cases* ? Those classes do nothing but return whatever the functions of the *repository* return. Is it done to make testing easy or will it be helpful if there are complex *use cases* ?
@uDropper
@uDropper 7 ай бұрын
When a import presents error just type 'flutter pub add [package name]' in the terminal
@tareksellami7346
@tareksellami7346 3 жыл бұрын
Thanks a lot for your great work
@moseskarunia
@moseskarunia 4 жыл бұрын
what a great tutorial! thanks
@TirthPatel
@TirthPatel 3 жыл бұрын
If there is a bottom navigation bar with 4 items then how can I divide them into features? There will be a scaffold that would host the BNV it the first place.
@luix138
@luix138 4 жыл бұрын
Hey teacher, I love your videos
@user-tr6ul3gy2t
@user-tr6ul3gy2t 11 ай бұрын
Does it make sense if we have an entity that has a member variable of type of another entity? Or am I doing the architecture incorrectly?
@eduardorabanal2803
@eduardorabanal2803 5 жыл бұрын
great video bro, I'm waiting for the next episode
@ahsanalidev
@ahsanalidev 4 жыл бұрын
you are doing great please keep it up , I am really thankful to you like really !!!! :-)
@THEMithrandir09
@THEMithrandir09 4 жыл бұрын
Why use Either(which I like) over basing the failure on number trivia? Any concrete reasoning on that?
@pathakvivek7865
@pathakvivek7865 5 жыл бұрын
you are awesome. Really quality content.
@jaboycjava
@jaboycjava 4 жыл бұрын
I recently watched through some of Uncle Bob's Clean Code videos, and one thing he says seems to contradict what you are doing. In this video, kzbin.info/www/bejne/a2nNeKOMZ6iaa5I, at 1:23:06, someone asks if the test suite should match the folder structure of the production code, and Uncle Bob says it shouldn't (due to coupling), but your test folder seems to match the folder structure of the production code. Can you help me understand whether I misunderstood something or what thoughts you have on this?
@aytunch
@aytunch 5 жыл бұрын
Matej, what are tests for exactly? I have never done tests before. Do they exist to check if repository feeds our logic methods with un processable data? Or would tests work for UI as well? What could be the benefits?
@guzidev
@guzidev 2 жыл бұрын
Nice videos, I have a question, What if we have an entity that needs to be called from multiple screens, maybe a game_topscore that can be required in game and top_score screens? We need to create core/domain/entities folder? Thank you
@RyanHooGeek
@RyanHooGeek 4 жыл бұрын
Strange accent, charming voice, great tutorial! Thank you so much.
@ResoCoder
@ResoCoder 4 жыл бұрын
Wannabe US accent with Slovak subtones 😄 Thanks for watching!
@meanwhile8811
@meanwhile8811 2 жыл бұрын
@@ResoCoder no offence but it sounds like you just got a set of new dentures. the fake yank accent be painful 😭⚰️
@ResoCoder
@ResoCoder 2 жыл бұрын
It’s not fake lol. I learned to speak English properly by watching a lot of Minecraft let’s plays as a kid mostly recorded by people from the US and Canada.
@meanwhile8811
@meanwhile8811 2 жыл бұрын
@@ResoCoder fair enough my guy. thanks for the lessons 😘
@goldcoderscorp1668
@goldcoderscorp1668 3 жыл бұрын
how would you go about using clean architecture on getx package?
@AimaneNajja
@AimaneNajja 4 жыл бұрын
Failure([List properties = const []]) : super(properties); [[]]; but this makes the test red because the Right-object expects a dynamic in it but a Failure-object is returned.. Please help
@jeancarloflorescarrasco412
@jeancarloflorescarrasco412 4 жыл бұрын
I'm facing the same error ...
@AimaneNajja
@AimaneNajja 4 жыл бұрын
For some reason it did not equal them even though the class extend Equatable. So what I did to make the test green was to make one instance for both thenAnswer and expect
@dawidniegrebecki2205
@dawidniegrebecki2205 4 жыл бұрын
Great video!!!
@bryanbarreto
@bryanbarreto 2 жыл бұрын
17:12 Using an external dependency on Domain doesn't break the rule that domain must not contain external dependecy? Because Domain is the most important layer of the application, and it's named domain because we mut have domain on everything on this layer. And importing DartZ break this rule. There's another solution for that?
@haidarrmehsen
@haidarrmehsen 4 жыл бұрын
Hello first thanks for the excellent explanation I just want to ask does this architecture fit for games developed with flutter as well? waiting for your response
@yuwenpixon
@yuwenpixon 4 жыл бұрын
What is the call to this architecture? sorry, I'm still confused, what is the difference, compared to other architecture like BLoc, Redux etc?
@gmc254quads6
@gmc254quads6 5 жыл бұрын
Thank you. Love the architecture and have started learning TDD.
KMP vs. Flutter - Who Will Win The Cross-Platform Battle?
16:19
Philipp Lackner
Рет қаралды 43 М.
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 3,3 МЛН
Unveiling my winning secret to defeating Maxim!😎| Free Fire Official
00:14
Garena Free Fire Global
Рет қаралды 9 МЛН
Кадр сыртындағы қызықтар | Келінжан
00:16
Pool Bed Prank By My Grandpa 😂 #funny
00:47
SKITS
Рет қаралды 20 МЛН
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 272 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 153 М.
E1: Clean Architecture in Next.js
2:58:53
Lazar Nikolov
Рет қаралды 36 М.
microsoft doubles down on recording your screen
10:00
Low Level Learning
Рет қаралды 67 М.
The Art of Code - Dylan Beattie
1:00:49
NDC Conferences
Рет қаралды 4,7 МЛН
Bloc Library - Painless State Management for Flutter
24:54
Reso Coder
Рет қаралды 92 М.
Flutter Testing Guide for Beginners - Part 1: Unit Tests & Setup
1:00:28
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 3,3 МЛН