.NET 5 REST API Tutorial 10 - Unit Testing and TDD

preview_player
Показать описание

Topics covered:
00:00 Video overview
00:41 What is Unit Testing?
04:56 What is Test Driven Development (TDD)?
07:12 Unit testing frameworks in .NET
08:02 Moving the REST API to its own directory
12:02 Creating the xUnit test project
18:13 Adding the test class
19:48 Adding tests for GetItemAsync
22:12 The AAA pattern
23:11 Adding stubs via the Moq framework
30:29 Running tests in VS Code
31:42 Using the .NET Core Test Explorer extension
41:38 Comparing object properties via FluentAssertions
45:22 Testing GetItemsAsync
49:19 Testing CreateItemAsync
54:38 Excluding missing members when comparing objects
56:50 Testing UpdateItemAsync
1:01:29 Testing DeleteItemAsync
1:03:34 Switching Item from record to class and adding Description
1:04:54 Switching DTOs to positional records
1:07:50 Fixing the code base
1:11:07 Fixing a failing test
1:14:27 Using TDD to add a new feature
1:15:41 Adding a test before implementing the new functionality
1:20:59 Auto generating the new method to implement
1:22:47 Getting green by implementing the new functionality
1:24:56 Verifying the new feature via Postman

#dotnet #restapi #tutorial
Рекомендации по теме
Комментарии
Автор

Hi Julio, Thank you very much for taking the time to make this video on Unit Testing and TDD in .NET5. I truly appreciate the effort.

Firstly, I would like to let you know that I have directly jumped to this video from the search and haven't watched other videos in this series as I am specifically looking for best practices on TDD. So if I have missed out on something then please feel free to point me in the right direction.

Now on to my

From the third section in this video, titled "What is Test Driven Development (TDD)?" (starting from 4:56), I have the following understanding:

A) Before you write any code, you write a test.
B) The test that is written is expected to fail because there is no code or implementations written for it. This is the Red Phase.
C) You then write just enough code that is required to make the failing test pass. This is the Green Phase.
D) You then write code to improve or add more functionality. This is the Blue/Refactor Phase.

My questions here are as follows:

1) Where is all this in the video?
2) Could you please point me to where you are writing your first test without having written any sort of other code or implementation? And where this first test fails?
3) Could you please point me to where you are demonstrating the RED-GREEN-BLUE/REFACTOR phases? It seems that the first test that you have written in the video starting from 19:48 to 31:03 has already passed i.e its Green without being Red.
4) Furthermore, the WebApi project that you have used in the video has an ItemsController pre-defined and implemented. The depending repositories and its interfaces are also pre-defined and implemented. This seems to go against point A above (and against the principles of TDD) no?

webnoel
Автор

Thanks for this episode, I was looking for a great tutorial on unit tests in .NET 5.0. It helped me a lot.

SadPhoenixLR
Автор

Hi Julio, thank you for the amazing content. These tutorials are clearly to understand and follow. We can see your great experience explaining and applying the topics. I'm sure that you are a great person and professional. THANK YOU, BRO!

santiagogilserna
Автор

Thank you Julio! Hoping for more series on .NET Core! :) As a newbie to Core, I learned much!

samanthamonteiro
Автор

You are amazing, Julio! Thanks again!

adrielairaldo
Автор

Hi Julio, very amazing Content, really Thank you!!!

alejandromachacanavia
Автор

Really good tutorial and especially the usage of FluentAssertions!

soucianceeqdamrashti
Автор

As always, clear and concise :) . Thanks for sharing Julio . Looking forward to see more of your contents :)

orneyd
Автор

Hi, Julio! In the GET method (around 43:20) you create the expectedItem (line 41). Later in the Assert (line 52), you are comparing the result (from line 49) with the expectedItem. Since the call to the repo is fake and no 'real' data is fetched, what is the point of comparing two things that are by definition equal?

JohnSourvinos
Автор

Hi Julio, Thank you for putting up this wonderful content. This is really helpful.

abyshekhar
Автор

Thank you so much, i love this series!

rhdwrrr
Автор

Hello Julio, I want to say that your tutorials are the best it really helped me, I'm looking forward to more videos.
If possible I would like you to add Authentication so the project will be more complete.

yassinrebai
Автор

Fantástico Julio!! Just some ideas for future episodes: code coverage, automapper, validation with fluent validation, autofac...

AHS
Автор

Excellent series Julio!
Now can you please create production ready .NET 5 course that uses Blazor and some fancy frontend framework like React's AntDesign? I would love to see visually stunning .NET 5 project and would be the first in line to buy it!
Thank you so much!

fieryscorpion
Автор

Hello Julio. Thank you for some really great content. Its is really easy to follow and understand. Some suggestions for future videos could be implementing a message system like RabbitMQ, maybe a video about Caching, or creating Api Gateways. That would be really great and again, thank you for the great content.

Noxxiee.
Автор

Okay I got it all building and working!

I am having a little difficulty figuring out how to deploy it now as the kind of "final stage" if you will. I started tinkering around with github actions to see if I could figure it out on my own but I can't quite get there.

I tinkered a bit with the dockerfile and got the image to build for the catalog csproj itself but the kubernetes deployment step I feel quite lost on.

The github actions template for GKE uses something called kustomize but I wasnt able to figure out how it worked from their website and I'm not entirely sure what it does or what it's expecting.
I'm also not sure if I should be also building the image for the mongodb and then writing some kind of step for both of those images for my GKE deploy.

Do you happen to know of any resources I could learn about this in video form? the documentation websites are too confusing for me :/

runnerup
Автор

Hi Julio, thank you so much for the tutorial, I learned a lot!
One question, everything seems okay at the end, it passes every test, but when I query the items in Postman, the 'Description' field that we added in the code isn't showing up on the JSON results at all. Can you point me in the direction of what could be causing this?

BrunoTheLegendKiller
Автор

Thank you Julio for the great tutorials, I've learned a lot. Would you be able to cover Unit Testing for CQRS & Repository pattern?

ThinhTran-yusn
Автор

Great video again as I said. Tell me Julio, using Moq is good to start and validate parts of the code, how ca we switch our unit tests once the other team for example responsable for the repository coding has finished, handed the code in a nuget package as you do in the course? I have the impression that we need to rewrite the unit tests once we need to start unit testing with real code and not mocked code

eliassal
Автор

Hello, Julio. Thank you for your videos. They are brilliant. Can you please make some videos on User Authentication as well for us?

alessanderboy
visit shbcf.ru