Writing tests in .NET using xUnit - xUnit Tutorial

  Рет қаралды 127,464

Nick Chapsas

Nick Chapsas

Күн бұрын

Become a Patreon and get source code access: / nickchapsas
Check out my courses: dometrain.com
The giveaway is now over. Thanks for participating.
Hello everybody I'm Nick and in this .NET tutorial I will teach you how you can write unit tests .NET Core using the xUnit library. xUnit is the most popular testing library in .NET and it is an essential part of your skillset.
Give xUnit a star: github.com/xunit/xunit
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasGitHub
Follow me on Twitter: bit.ly/ChapsasTwitter
Connect on LinkedIn: bit.ly/ChapsasLinkedIn
#dotnet #xunit #tests

Пікірлер: 69
@nickchapsas
@nickchapsas 2 жыл бұрын
Are you looking for more training? Check out my "From Zero to Hero: Unit testing in C#" course: nickchapsas.com/p/from-zero-to-hero-unit-testing-in-c
@TheEamonKeane
@TheEamonKeane 3 жыл бұрын
just found your channel a week ago. Really high-quality content! keep it up
@BeansEnjoyer911
@BeansEnjoyer911 2 жыл бұрын
I wasn't convinced. But about a third of the way through.... This is amazing! Will definitely look into this package
@RandomVlogsToShare
@RandomVlogsToShare 3 жыл бұрын
Great video, nicely explained and you have kept it simple and easy to understand. Thank you.
@darkarmo
@darkarmo 4 жыл бұрын
Great video! didn't know about the ClassData, thanks!
@serhiihorun6298
@serhiihorun6298 4 жыл бұрын
Thanks for the tutorials! They are superb!
@iwayansudiana4897
@iwayansudiana4897 4 жыл бұрын
Thanks man! It helps me to start my testing.
@stratman1234
@stratman1234 3 жыл бұрын
This has been a huge help. Before watching your video, I only know about [Fact] and [Theory][InlineData].
@tuberklz
@tuberklz 2 жыл бұрын
yet again great tutorial. thanks for all the effort
@vmamore
@vmamore 4 жыл бұрын
Awesome Nick, thank you!
@Chiramisudo
@Chiramisudo 2 жыл бұрын
Outstanding! This is the ideal video for me. A bunch of real code examples showcasing the full feature set (or at least the most important ones) along with a little explanation as to limitations, use cases, etc. Perfecto!! The only constructive criticism I have is that (on my desktop speakers at least) the sound is a bit muddled and bassy for voice.
@nstohler75
@nstohler75 4 жыл бұрын
Great video, thanks Nick! I've just finished reading Vladimir Khorikovs book on Unit Testing and would recommend that one to every one who is interested in the topic! Also, his article "You are naming your tests wrong!" is a great read.
@nickchapsas
@nickchapsas 4 жыл бұрын
Keep in mind this is not about unit testing but about how to use the xUnit library. I already have a video talking about TDD and I go more in depth about naming and structure.
@nstohler75
@nstohler75 4 жыл бұрын
@@nickchapsas Yes, your other video is great too, I've learned a lot about TDD and xUnit there already, and it led me to dig deep into the topics. I've applied everything I learned to a new project and must say it is very nice to have all the tests as a safety net!
@serhiihorun6298
@serhiihorun6298 4 жыл бұрын
Great video, thank you!
@donnyjoe7653
@donnyjoe7653 3 жыл бұрын
Didn't expect this video to go beyond beginner's level and turned out to be extremely useful condensed and clear information. I just created a new private playlist for favorites to add this in. Mille Grazie! :*
@nstohler75
@nstohler75 4 жыл бұрын
Some ideas for your next unit testing videos: - How to write more elegant tests with FluentAssertions - When and how to use mocks, when to avoid - How to test the EF Core Queries using InMemory Database Provider - AutoFixture - good or bad? - Blazor projects: how to test pages - MediatR: how to test commands/queries
@nickchapsas
@nickchapsas 4 жыл бұрын
Great ideas! I have a video for both FluentAssetions, Shouldly, Moq, FakeItEasy, NSubstitude and AutoFixture in the pipeline alongside 25-30 other libraries :D I actually made a video on Blazor testing but I had to scrap it because Microsoft will eventually come out with their own testing package and will render my video obsolete.
@shaunsuzor3758
@shaunsuzor3758 3 жыл бұрын
Vç]
@barwalgayatri4655
@barwalgayatri4655 Жыл бұрын
Too good and informative videos Nick. proud to be ur subscriber :)
@davidpccode
@davidpccode 4 жыл бұрын
Great vid.. thank you!!
@compman73
@compman73 3 жыл бұрын
Thank you It was very helpful
@cyberdragon852
@cyberdragon852 Жыл бұрын
Very helpful thank you
@adamlasry5225
@adamlasry5225 11 ай бұрын
Brilliant. Thanks.
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 4 жыл бұрын
Good tutorial!
@saaddahmani1870
@saaddahmani1870 4 жыл бұрын
Very very helpful video... thanks
@mdabuzar2130
@mdabuzar2130 3 жыл бұрын
As usual, the best video.
@igor5379
@igor5379 3 жыл бұрын
thanks, bro!
@muhamedkarajic
@muhamedkarajic 2 жыл бұрын
Great Tutorial Indeed!
@JesperPetersen
@JesperPetersen 3 жыл бұрын
It's so that I thought about whether you could make a video where you have a project, service, data and testing. It's because I'm in trouble compared to when I need something in service that I can not access the database. I have researched a bit in relation to stackoverflow around it and there I could read my way to "You can not use appsettings.json as Configuration in test project from Web project. If you want to use, you should make a custom implementation" Thanks for video.
@TarekFaham
@TarekFaham 2 жыл бұрын
Thank you so much... What if you want to initialize selenium chrome driver using some parameters how you will inject it in the constructor?
@ghostslinger3148
@ghostslinger3148 2 жыл бұрын
Hi Nick, great video! Do you have a video going through unit tests using InMemoryDatabase db context? I run into problem "An item with the same key has already been added" when running multiple unit test files when initializing the same context even when i already added IDisposable and EnsureDeleted. Is it just bad to do unit test using this way?
@VG-vn8kk
@VG-vn8kk 4 жыл бұрын
Thank you very much for your videos, Nick! I'm learning a lot! Would it be possible for you to create a little practical tutorial on how to test API controllers and services which talk to the database layer with xUnit?
@nickchapsas
@nickchapsas 4 жыл бұрын
It’s your lucky day. The next 3 videos will be about mocking 😃
@VG-vn8kk
@VG-vn8kk 4 жыл бұрын
@@nickchapsas Thanks, man! Really appreciate you sharing your knowledge. And your short, strait to the point videos are very-very helpful.
@lorenzoshawn7969
@lorenzoshawn7969 3 жыл бұрын
I guess it's kinda randomly asking but does anybody know a good site to watch newly released series online?
@hassanmaxton7942
@hassanmaxton7942 3 жыл бұрын
@Lorenzo Shawn flixportal xD
@lorenzoshawn7969
@lorenzoshawn7969 3 жыл бұрын
@Hassan Maxton Thanks, I signed up and it seems like a nice service :D I appreciate it !
@sairk6174
@sairk6174 4 жыл бұрын
AWESOME .. NICK THANKS FOR EXCELLENT VIDEOS ..CAN YOU PLEASE CHECK POSSIBILITIES FOR SOME VIDS ON CLIENT SIDE UNIT TESTING ..USING JASMINE??
@MA-pt6ii
@MA-pt6ii 3 жыл бұрын
Hi Great video...I am trying to implement extent reporting using Extent reporting using Selenium c# with Xunit. are you able to guide me details of how to implement this in my framework
@flave11
@flave11 4 жыл бұрын
Very nice
@yassineyounes3479
@yassineyounes3479 4 жыл бұрын
Great video! keep up the good work!
@alfredoquintanalopez2265
@alfredoquintanalopez2265 4 жыл бұрын
Could you please make a video about NUnit? Thanks a lot!!!!!. Great videos!!!
@TonoNamnum
@TonoNamnum 3 жыл бұрын
Is it bad practice to use a static property containing the dependencies instead of using a context?
@zerosandones7547
@zerosandones7547 2 жыл бұрын
Do we need to suffix "Theory" in every [Theory] method? Like is it best practice?
@lucianocuesta1170
@lucianocuesta1170 3 жыл бұрын
what about Component test, can we use xUNIT for that propouse?
@vaibhavmalhotra5644
@vaibhavmalhotra5644 4 жыл бұрын
how does your visual studio look so different?
@Steve3dot1416
@Steve3dot1416 Жыл бұрын
19:58. I am confused. If each one of the two test call RandomGuid, it should return a random one each time even if the guid generator is the same instance between each test. How come they return the same value?
@harag9
@harag9 3 жыл бұрын
Thanks for this, though it was quick, it's very useful... But - Who tests the tests?
@mchen0901
@mchen0901 4 жыл бұрын
Hi there, do you mind providing a tutorial for AssemblyFixture? CollectionFixture doesnt work for me since it requires all involved tests to be executed sequentially, but I need parallelism Thank you!
@nickchapsas
@nickchapsas 4 жыл бұрын
Hey Mike, I wasn't aware of AssemblyFixture. I don't know if I will make a video about it but I could write a blog.
@ibknl1986
@ibknl1986 2 жыл бұрын
Nice video.
@zevspitz8925
@zevspitz8925 2 жыл бұрын
Why does TestData need to be an iterator function? Let it return the data from a static field. (Or better yet, allow MemberData to use fields directly; but that's apparently an xUnit design choice.)
@nickchapsas
@nickchapsas 2 жыл бұрын
It's an iterator because xUnit will use it to iterate over them in an efficient way to execute
@zevspitz8925
@zevspitz8925 2 жыл бұрын
@@nickchapsas Would it be more efficient than a method which returns the same IEnumerable from a static field, storing the entire set as an object[][], or List?
@nickchapsas
@nickchapsas 2 жыл бұрын
@@zevspitz8925 xUnit is lazily reading the cases so the full array isn't enumerated part the point of the current testing case, so yeah it would be more efficient
@longb1913
@longb1913 Жыл бұрын
where do u get CalculatorState from in the calculator class? wtf
@andriyzubyk629
@andriyzubyk629 4 жыл бұрын
#JetBrainsRide thanks for your videos)
@taylorjonl
@taylorjonl Жыл бұрын
Great beginner video but the information about the tests running in parallel is incorrect. Tests within a class will not run in parallel because by default xunit create a test collection per class. You can switch the behavior to create a collection per assembly but you can't go to a lower level than class AFAIK. Also, if you use CollectionDefinitions that use fixtures, you need to ensure you define the CollectionDefinition in the assembly with the tests, otherwise the fixtures part of the CollectionDefinition isn't recognized and it won't create the fixtures, silently failing. After 4 hours I found single sentence in the documentation that states this.
@ChrisByram
@ChrisByram Жыл бұрын
I'd suspect it might be version differences. This video is 3 years old and at least one major version has happened since then.
@clearlyunwell
@clearlyunwell 3 жыл бұрын
👍🏽
@VladyslavPavliuk
@VladyslavPavliuk 4 жыл бұрын
#JetBrainsRider
@medachref7167
@medachref7167 2 жыл бұрын
hahaha because my pc is too fast
@Fasiibcs
@Fasiibcs 4 жыл бұрын
Your speed is too fast, I know about unit test but not know about xUnit so it is hard to grasp the detail that much quick. Your videos are good, but please try to slow down your speed and explain thing is little more detail.
@krzysztofurban4561
@krzysztofurban4561 4 жыл бұрын
You always can reduce speed using youtube video setting (for example set speed to 0.75)
@fabrizziocht
@fabrizziocht 4 жыл бұрын
Great video, thank you!!
@sunpakky
@sunpakky 4 жыл бұрын
#JetBrainsRider
Why We ALL Use xUnit over NUnit or MSTest?
17:51
Gui Ferreira
Рет қаралды 8 М.
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 16 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 35 МЛН
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 13 МЛН
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
You are doing .NET logging wrong. Let's fix it
25:29
Nick Chapsas
Рет қаралды 171 М.
C# Unit Testing Tutorial For Beginners
45:09
Julio Casal
Рет қаралды 4,3 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 255 М.
C# Unit Testing - Full Course - Write Unit Tests in C# like a pro!
1:22:12
tutorialsEU - C#
Рет қаралды 42 М.
Integration testing | ASP.NET Core 5 REST API Tutorial 15
22:13
Nick Chapsas
Рет қаралды 110 М.
Don’t Use UUIDs/GUIDs in Databases. Use this Instead
10:36
Nick Chapsas
Рет қаралды 38 М.
Write Unit Tests Against the Interface, Not Implementation
12:17
Zoran Horvat
Рет қаралды 6 М.
Unit-тесты в .NET с использованием xUnit
17:02
Intro to Unit Testing in C# using XUnit
1:42:09
IAmTimCorey
Рет қаралды 411 М.
The cleanest way to use Docker for testing in .NET
13:36
Nick Chapsas
Рет қаралды 87 М.
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 16 МЛН