Testing in .NET is About to Change

  Рет қаралды 82,397

Nick Chapsas

Nick Chapsas

Күн бұрын

Until the 30th of September get 30% off any course on Dometrain with code BTS30: dometrain.com/...
Subscribe to my weekly newsletter: nickchapsas.com
Become a Patreon and get special perks: / nickchapsas
Hello, everybody, I'm Nick, and in this video I will introduce you to a brand new testing library in .NET called TUnit. TUnit aims to be the new way of doing testing in .NET and I am very excited about its future.
Give TUnit a star on GitHub: github.com/tho...
Workshops: bit.ly/nickwor...
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: github.com/Elf...
Follow me on Twitter: / nickchapsas
Connect on LinkedIn: / nick-chapsas
Keep coding merch: keepcoding.shop
#csharp #dotnet #codecop

Пікірлер: 296
@JackTheSpades
@JackTheSpades 2 ай бұрын
Personally I prefer PUnit. Testing in Production :3
@IsaacOjeda
@IsaacOjeda 2 ай бұрын
🤣🤣🤣
@MrMelick
@MrMelick 2 ай бұрын
@@IsaacOjeda The Crowdstrike method
@PatrickMageez
@PatrickMageez 2 ай бұрын
This comment made my day thank you
@watherby29
@watherby29 2 ай бұрын
Are you a Microsoftie?
@messirekhagen
@messirekhagen 2 ай бұрын
yeah, it the best. cause user-generated scenarios
@sergeybenzenko6629
@sergeybenzenko6629 2 ай бұрын
We have shitty tests that randomly fail and depend on one another. Now we got a perfect framework to hide it and not having to fix these damn tests. YAY!!!
@fredrikjosefsson3373
@fredrikjosefsson3373 2 ай бұрын
lol recently I started to have some tests (exactly 14 tests) fail the first time I run all tests, but when I rerun them it works. It has something to do with TimeProvider, and the error is "Cannot set the time into the future" or something. I have no idea why they fail because the time provided is hardcoded. Luckily they never fail in the test pipeline
@nickbarton3191
@nickbarton3191 Ай бұрын
Same, if run in parallel they break. It's not the units, but the tests don't inject dependencies independent from one another. They were written after the code. We'll do it right next project, lol.
@GioacchinoPiazzolla
@GioacchinoPiazzolla Ай бұрын
​@@fredrikjosefsson3373 Do your tests read the appsettings.json file? If I may ask.
@markovcd
@markovcd 2 ай бұрын
Now I can over-engineer my tests easier than ever! ;)
@mariusg8824
@mariusg8824 2 ай бұрын
NUnit also has testplatform support. NUnit also has most of the test preparation hooks demonstrated here, and also supports awaitable tasks. So, I think this video is a bit misleading. The most relevant information (and thanks for that!) is that dotnet changed its test execution strategy, and this is actually really useful.
@DoorThief
@DoorThief 2 ай бұрын
This is pretty cool. If I'm writing unit tests, its true I might not see the value with this framework if all my tests are perfectly isolated. But for integration tests/UI tests, i can finally not have it run in one giant method and finally have test order control! This is really useful for different types of testing.
@ThugLifeModafocah
@ThugLifeModafocah 2 ай бұрын
even with unit you have less configuration to be used. You don't need to inherit from shit, you have it as a more direct approach.
@fredrikjosefsson3373
@fredrikjosefsson3373 2 ай бұрын
many of our tests basically do Test1: see if thing 1 works, Test2: see if thing 2 works(which also requires thing 1 to work) Test3: see if thing 3 works(which requires the 2 earlier to work) so the DependsOn is something that I think can be useful. The previous tests checks that the current states are as they should be, so could of course all be put into one test, but having different tests for different purposes is better in my opinion. Like if I want to test that when I start an activity it should have x,y,z and another test checks when the activity is in progress and should then have a,b,c etc
@vornamenachname906
@vornamenachname906 20 күн бұрын
Nunit3 has perfect order control and also you can disable parallelism. Just use [Test, Order(1)] void mytest1() And use [disableParallel] on the test class (you must look up the exact word but there is something like this)
@anth9623
@anth9623 2 ай бұрын
Hmmm maybe overtime it will show more advantages over other testing frameworks, but NUnit/XUnit are both decent, well supported, and feature rich, so it does make it more difficult to switch at the moment. But that being said, it's new and no doubt will get better, so who knows 😊
@BetrayedEnemy
@BetrayedEnemy 2 ай бұрын
Liked for "Assert DOT THAT DOT IS DOT " -Dance
@Dustyy01
@Dustyy01 2 ай бұрын
You mean this kzbin.infoUgkx-4EdhRx-UT3dlAvXrm1yaPxkCOGV74EQ?si=gFuOk8PJd8Nnx8E1
@CarlintVeld
@CarlintVeld 2 ай бұрын
@nickchapsas can you provide fluent examples that you prefer?
@ryanelfman3520
@ryanelfman3520 2 ай бұрын
So much hate in these comments. If you’ve never ran into the limitations of xUnit then you wouldn’t realize the benefits. A lot of people override the standard xUnit framework because parallelization in xUnit is bad and not as configurable as it should be. Once you do that it’s extremely difficult to use spec flow on top of it or some other framework This is excellent to see its source generated. It’s the way to go
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф 2 ай бұрын
If you have parallelisation issues with unit tests you definitely have bigger problem than xUnit
@cronaldopwns
@cronaldopwns 2 ай бұрын
@@ВладиславДараган-ш3ф this
@queenstownswords
@queenstownswords 2 ай бұрын
1. I am wondering is SpecFlow dead and Reqnroll is the replacement 2. How long until we have support for other frameworks - i.e. Reqnroll?
@banksy215
@banksy215 2 ай бұрын
If you're using spec flow you have bigger issues than xUnit
@denys-p
@denys-p 2 ай бұрын
It is not hate, it is just sad realization how it will be misused in so many ways, making codebase worse. For example, when last time I was asked to check what the problem with test parallelization, it turned out to be not problem in tests, but race condition in code under test. And such things will just mask underlying problems by setting “proper” order and parallelization settings in tests
@okmarshall
@okmarshall 2 ай бұрын
This gets me excited. I'd love to see more stuff about parallel execution of tests and how this stuff works with Azure pipelines.
@PeteRobinson-gb7nz
@PeteRobinson-gb7nz 2 ай бұрын
We need *test* frameworks not just *unit* test frameworks (we use them for more than just unit tests)
@davestorm6718
@davestorm6718 2 ай бұрын
I would like to see simpler scaffolding for testing databases and apis, especially when it comes to delays, intermittent connections, corrupted data, partial data, really slow responses, connection strings, security [certs, encryption,etc] and more. While things like an in-memory database are good, it'd be nice to test more realistic scenarios with a project, so you can handle things better.
@sergeyz.5845
@sergeyz.5845 2 ай бұрын
Really need a blazor testing video
@softwaretechnologyengineering
@softwaretechnologyengineering 2 ай бұрын
Before assembly, what a fantastic way to hide weird behaviour in a large test suite.
@cyril113
@cyril113 2 ай бұрын
Because doing things before tests is weird. And how is it going to hide it if the code that runs is annotated with Before(Assembly)?
@nickchapsas
@nickchapsas 2 ай бұрын
Not true for acceptance tests where you’re spinning up a bit suite of tests.
@softwaretechnologyengineering
@softwaretechnologyengineering 2 ай бұрын
You got a large amount of files in an assembly. A problem in one file and this thing in an unrelated file causing the issue. Seems like it would be annoying.
@NickSteffen
@NickSteffen 2 ай бұрын
Most existing tests I’ve run across just leave the weird behavior in place and let their pipelines fail occasionally. People hate troubleshooting tests because most of these times the issue is in the test code and not the code being tested so they view it as a waste of time. I personally will fix them as I come across but I definitely respect the opinion that if you could just add a depends on attribute to make the order explicitz and quickly fix the issue that might be the worthwhile solution. I’ll still come by and fix it later for you but not everyone needs to be testing experts.
@Thomhurst
@Thomhurst 2 ай бұрын
One usage where this can be beneficial is running your tests against an in memory server. You can start it before your tests, and dispose it after.
@nickst0ne
@nickst0ne 2 ай бұрын
Thanks Nick. It's interesting to discover new libraries, though I don't see myself using this one before years. The Retry feature is a real plus. When a 2-hours long CI/CD fails for the third time because of flaky unit tests (among ~40,000 unit tests in the solution) you want to see the world burn. All the rest, I don't think I've encountered situations where Xunit was limited.
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф 2 ай бұрын
If you have a flaky code, then you need to fix the code, not adapt the freaking tests, dude. It is not acceptable to have a flaky code in a first place.
@fritzfahrmann4730
@fritzfahrmann4730 2 ай бұрын
Nunit also has retry since a long time
@MatinDevs
@MatinDevs 2 ай бұрын
2:15 I love how nick chooses "random" numbers
@local9
@local9 2 ай бұрын
If only the test ran for 260 seconds too
@CodySkidmorenh
@CodySkidmorenh Ай бұрын
The Arguments attribute was implemented in MbUnit almost 20 years ago. I loved that testing framework.
@JustArion
@JustArion 2 ай бұрын
I wonder what would happen if there's a circular dependency of tests. A depends on B. B depends on A. Hopefully a runtime exception. Worst case is a deadlock...
@Thomhurst
@Thomhurst 2 ай бұрын
Hey @JustArion there's a compile time analyzer and also a runtime exception (for if you'd disabled analyzers)
@BrianBehm
@BrianBehm 2 ай бұрын
What about support for build pipelines? Are there any pros and cons there?
@xtazyxxx3487
@xtazyxxx3487 2 ай бұрын
Use dotnet test in ur pipelines
@vornamenachname906
@vornamenachname906 20 күн бұрын
Having the test result in the Before hook makes so much sense... I can now async wait for the result in the before hook to see the result later, so i can continue overengineering.
@Synesthesia-r9
@Synesthesia-r9 2 ай бұрын
Are there any other unit testing libraries that use the new testing platform?
@EikeSchwass
@EikeSchwass 2 ай бұрын
I think NUnit has support for it
@xBalaDeCanhaox
@xBalaDeCanhaox 2 ай бұрын
This is awesome as we don't need vstest host anymore and I personally hate it.
@jwmoffat
@jwmoffat 2 ай бұрын
DependsOn is pretty much what I've wanted for a number of my integration tests. Thanks for sharing!
@loganbus
@loganbus 2 ай бұрын
Looks exciting, but I was hoping to see property-based unit testing here. Patiently waiting for the first library that makes it really accessible for .NET.
@z0nx
@z0nx 2 ай бұрын
What's wrong with CsCheck?
@AnythingGodamnit
@AnythingGodamnit 2 ай бұрын
FsCheck is not accessible?
@SADS-810
@SADS-810 2 ай бұрын
I love this framework and I love the assertions too, because I like my assertions to both start with "Assert" so that I can scan them in the code easily and also to be fluent. I can proudly say that I am this project's first sponsor!
@hellowill
@hellowill 2 ай бұрын
All they did is copy java
@sneer0101
@sneer0101 2 ай бұрын
​@@hellowill Grow up
@gweltazlemartret6760
@gweltazlemartret6760 14 күн бұрын
Note that it’s English fluent. It makes little sense to someone whose english is not their native language. Little of computer science does indeed. So please, stop "fluenting" things just for your side of the Atlantic ocean. Assert.IsEqual(a, b) used to be fine, Assert.That(a).IsEqualTo(b) is nowhere near fluenter. I do love the project tho, and will avocate for its use on next projects.
@frankroos1167
@frankroos1167 Ай бұрын
DependsOn can be useful in unit testing. If my method has a lot of code, that is covered by multiple tests, then a change that will make a test of a piece of code that is early in the method faile will make a lot of tests fail. If the tests for the later code depend on the test of the early code, then it will be much clearer in the test results where te problem is.
@SandstormNick_1
@SandstormNick_1 2 ай бұрын
18 Sept, version = 0.1.752. 21 Sept, version = 0.1.793 Pumping out the updates
@dahahaka
@dahahaka 2 ай бұрын
I use GUnit
@timur2887
@timur2887 2 ай бұрын
TestsSucksUnit =)
@alanwakeup3344
@alanwakeup3344 2 ай бұрын
All that hype in the beginning for a more granular [SetUp] attribute o_O?
@EikeSchwass
@EikeSchwass 2 ай бұрын
Personally I think the ConstructorInjection concept is really great and it really shines when you have complex setup/teardowns, because it gives you so much flexibility and control
@mirrorless_mirror
@mirrorless_mirror 2 ай бұрын
Assert.That(x).IsEqualTo(y) is actually the same approach as in the Java library Assert4J
@kinsondigital
@kinsondigital 2 ай бұрын
Oh hell yes! I likey!! Yeah, this should get some funding sent it's way for sure.
@ArnabDeveloper
@ArnabDeveloper 2 ай бұрын
Great video. The before all and before each reminds me about Pester which is a PowerShell test tool.
@carlitoz450
@carlitoz450 2 ай бұрын
how could ever a test depends on another test ? in my humble opinion, tests should be indepedent no matter what.
@bitmanagent67
@bitmanagent67 2 ай бұрын
Would you test deletion of a record before creating it? Would you test fulfilling an order if the payment gateway returned unsuccessful for payment? With unit testing your assertion stands valid. With integration testing, you are testing the integration of multiple services or scenarios, no matter what.
@carlitoz450
@carlitoz450 2 ай бұрын
@@bitmanagent67 in this type of situation, it's the "arrange" portion of the test that should set the table. Not the result of another test
@paul.fletcher
@paul.fletcher 2 ай бұрын
@@carlitoz450 sounds like semantics to me.
@carlitoz450
@carlitoz450 Ай бұрын
@@paul.fletcher i agree, my point is the feature "depends on" to make sure that another test ends before.... is just against the rule that a test should be independent
@renynzea
@renynzea 2 ай бұрын
Two things: When you do the full video, I would like to see how you would emulation collection fixtures in XUnit. My guess, looking at the preview, is that I would create a base class that implements `BeforeAssembly`, wire up a static property on the base class, then in all my child tests I could access that. (E.g. for an EF Context, some class that wraps API requests, etc.) Second thing, what are your thoughts on creating an abstraction around asserts? Cause it seems like every assert library decides to do things its own way, and if you switch libraries that ends up being the worse part of the migration; changing all the asserts. If you abstracted that out into your own assert classes, and had different concrete implementations for different test libraries you could more easily swap the asserts out by just changing how you implement them in the abstractions. You'd still have to fix the test attributes, but that could probably be done through a mass find/replace.
@vendre2
@vendre2 2 ай бұрын
Me personally I like xunit approach, each classes has constructors and disposability or destructors and more natural then attribute mountains and more independent and more threadsafe int that way. But the only benefit is the speed because of the generated code and that's it. I did not like to much yet however can have potential
@EikeSchwass
@EikeSchwass 2 ай бұрын
You can use constructors and dispose in TUnit as well, IIRC
@F1nalspace
@F1nalspace 2 ай бұрын
I must admit, i never used any 3rd party for unit-testing in .NET. So every library is most likely better than the one we use: MS-Test. But T-Unit looks good so far and i really like it too that you have lots of control over it. But don't like the assertions. I would rather have manual Assert.IsTrue, IsFalse, AreEqual, etc. If i want that chaining thing, i would use fluent assertions. But myself would never use that, because i really hate chaining api's in general. I think its a stupid idea and i see no benefits of that pattern at all. It looks nice, writing a one liner but as soon as your line exceeds the editor width or has more than two lines - then it gets less readable and gets extremely hard to debug.
@Thomhurst
@Thomhurst 2 ай бұрын
Thanks for the feedback. You're not tied to the TUnit assertions and can use whichever library you like!
@M0J0-RL236
@M0J0-RL236 2 ай бұрын
Agree, i use an old version of NUnit just to keep Assert.True and Assert.AreEqual etc
@ahmedma527
@ahmedma527 Ай бұрын
Thanks. What is the best free mocking framework without limitation like in mocking static class or extension method?
@andriisnihyr6497
@andriisnihyr6497 Ай бұрын
Thanks for sharing this, Nick! Personally, I have mixed feeling about it. I definingly see a lot of benefits it brings for integration tests. For unit tests, the only real benefits are speed and a bit more control on the setup/teardown of the test. I'm a bit worried to open up the test project one day and see a complex graph of test dependencies along with bunch of retries... :/
@Punkologist
@Punkologist Ай бұрын
So after a year after paying for it, I finally got around to doing your unit testing course. I'm loving it and working on implementing it everywhere.. Now you tell me Xunit is obsolete! 🤣
@JorgeLuisMachadoTorres
@JorgeLuisMachadoTorres 2 ай бұрын
Would be possible to do one to see how test coverage looks like with this new lib
@JonathanPeel
@JonathanPeel 2 ай бұрын
XUnit and NUnit both work very well in F#. If TUnit is using source generators I am guessing it would be C# olnly.
@ЕгорФедоренко-с2щ
@ЕгорФедоренко-с2щ Ай бұрын
A lot of discussions here about tests should be independent, tests shouldn’t have a complex SetUp, etc. Guys, have you ever seen UI test? It’s a true mess. You ANY-WAY will have such things like depending tests on each other, huge set-ups, both for class and for each test, and yeah, this ObjectBag thing will be useful too. I find this project just perfect for UI testing, very excited to rewrite the entire 8k-tests-framework with it 😅 Ah, dreams… P.S. By the way, parallelism is a must in UI testing too, otherwise you will be waiting results for a couple of days instead of 6-8 hours. So built-in parallelism is a great one, too.
@TheOceanLoader
@TheOceanLoader Ай бұрын
In the UK, it's nUnit preferred over xUnit and MSTest, but I think I will be advocating for TUnit. Might have been good adding TUnit in the title of this video as I watched it thinking it was part of the next update to .NET
@nickchapsas
@nickchapsas Ай бұрын
Completely untrue. I’ve worked at ASOS and checkout.com and they all use xUnit. Same goes for Just eat, clear bank and many others
@R.B.
@R.B. 2 ай бұрын
The biggest problem I have with test arguments is that if you are using a matrix of test arguments and expected results, most frameworks see that as one test. I'd want to use the matrix of arguments to test the cases, and if one edge case fails, the entire test fails. What would make something like this more ideal for me is that the multiple test arguments are broken out, at least for reporting when there's a failure, as individual test cases. I think the idea of the Before decorator is good, but it would also be great if you could define categories of tests which depend on on or more of those setup methods, so that state might be reused but different fixtures might require different setup states and that could be used to apply what is needed for each test. There's a condition where one test might inherit two different conflicting states, so some thought needs to be put into that type of system, but I see a lot of potential.
@Thomhurst
@Thomhurst 2 ай бұрын
You can do [Before every(Class)] which would affect every fixture. But no reason you couldn't have an if statement in there and perform logic based on any information from the context object.
2 ай бұрын
Thanks for the info. As always, refactor all unit tests and use it in production even if it's in preview library, you will thank me later.
@tridy7893
@tridy7893 2 ай бұрын
There is no AI in it? Pfffff, what a waste. [ɯsɐɔɹɐs].
@nickchapsas
@nickchapsas 2 ай бұрын
AIUnit next
@lylobean
@lylobean 2 ай бұрын
He makes a good point chat gpt might not know how to write my tests in it. Yet.
@MattWanchap
@MattWanchap 2 ай бұрын
That sarcasm tag is brilliant! Don't know why but I've never seen it written like that before
@Mr767267
@Mr767267 2 ай бұрын
Tests were supposed to the simple and very less depending on anything else. I do understand the power it brings but it the question is does it really require it?
@AdamTheWilliams
@AdamTheWilliams 2 ай бұрын
would love to see you do a video putting o1-preview to the test
@Downicon3
@Downicon3 Ай бұрын
I like the Injectable Class Data Source
@burnt1ce85
@burnt1ce85 2 ай бұрын
Great video. Maybe in the next video, go over their benchmarks. Apparently TUnit is 10x faster than Nunit and TUnit_AOT is 75x faster. It would be great if you can verify this and the pros and cons of each method.
@smithkl42
@smithkl42 2 ай бұрын
I'm curious how the code generation performance works on large projects. I'd rather suffer through test discovery delays when I'm running tests than suffer through code generation delays every single time I build - but if the code generation/build step isn't particularly noticeable, that could be an interesting tweak.
@Thomhurst
@Thomhurst 2 ай бұрын
Heya! Ive got a benchmark on GitHub for building but admittedly it is a very minimal test project. I'd be happy to extend it but writing dummy tests in itself is a bit of effort so isn't the highest on my priority list right now. As for local development, it hopefully shouldn't affect you too much as it uses the newer incremental source generator. That means it only generates new source if it detects changes that would affect it. So hopefully it'll keep performance to an acceptable level!
@phizc
@phizc 2 ай бұрын
Source generators don't normally run at compile time. They run every time a file is changed. If you clone a repository, or clean the build artifacts directory, it takes a little time to generate the files, but once that's done they're normal C# files and shouldn't affect the built times much. In theory source generators could cause a lot of work every time you type a character, but incremental source generators do a quick analysis to see if the change would require it to regenerate the source. Most of the time it doesn't. I haven't read the source generators for TUnit, but I suspect it only needs to run the source generator when one of the attributes is changed or added. Tldr; it shouldn't cause much of an increase in build times.
@EikeSchwass
@EikeSchwass 2 ай бұрын
CodeGenerators are incremental, so you would only suffer the upfront cost once and then new tests will just add to the output, rather than trigger a full regeneration. I think it's a really nice idea
@positronalpha
@positronalpha Ай бұрын
Did you ever use Machine.Specifications? I loved it. Made so much sense.
@davemasters
@davemasters 2 ай бұрын
Hmm - I think I'll wait for xUnit v3. xUnit v2 does have major limitations when it comes to integration/acceptance tests that this library does seem to address, but I'm not keen on the level of flexibility this introduces which would potentially lead to some bad practices. xUnit v3 seems to address my issues with v2.
@Fred-yq3fs
@Fred-yq3fs 2 ай бұрын
I don t buy into stateful unit tests, before after and all that goop. I have a static creating the sut and dependencies, then the test method does arrange act assert. Everything s pure. No state, no hidden stuff no magic. For integration tests I use specflow.
@watherby29
@watherby29 2 ай бұрын
Will I be testing this test framework or is it stable to use?
@G41headache
@G41headache 2 ай бұрын
How quick is the source generation? Is it noticable?
@M0J0-RL236
@M0J0-RL236 2 ай бұрын
Am I missing something here or does NUnit + Moq and resharper perfectly sufficient? You can already pass in arguments, you can even specify a nameof and pass in an enumerable etc. I like when we could use Assert.True and Assert.NotNull etc rather than the wordy "Assert.That." syntax
@EikeSchwass
@EikeSchwass 2 ай бұрын
For simple UnitTests anything will work, but TUnit really shines in complex integration/acceptance test contexts
@denys-p
@denys-p 2 ай бұрын
Oh, I see so many ways how this library will be misused by developers. Instead of fixing flaky code that crumbles under tests, it will be just masked by set of attributes that will run tests in very specific order to make them green. “Before assembly” - wonderful way to shoot not only your leg, but also legs of your colleagues, who will guess what is happening there (and it happens somewhere 3 folders away where no one would search for it). Also, not a fan of async assertions. Why? We should already have results by the assertion time. The only thing I like so far - code generation (at least, “on paper” - didn’t try it yet). All other features will be misused way more often than used for good.
@CommentingOnTheFreakshow
@CommentingOnTheFreakshow Ай бұрын
Looks like the main release version of Visual Studio 2022 is not ready for prime time yet for TUnit. I couldn't make it work.
@ezrichie2006
@ezrichie2006 2 ай бұрын
really cool feature. bout to start migrating code to TUnit now. XD
@ipiptr
@ipiptr 2 ай бұрын
hi, nick. is it good to use net 9 rc for production?
@rngesus8057
@rngesus8057 2 ай бұрын
reminds me of the spec flow library
@evancombs5159
@evancombs5159 2 ай бұрын
Looks good, but not good enough to get me to switch any current projects over. Maybe try it for a greenfield project.
@SunnyPatel-z6k
@SunnyPatel-z6k 2 ай бұрын
Ah good old Tom :) great engineer back in ASOS days!
2 ай бұрын
The title of the video and the example was a bit confusing to me. My initial reaction was "Is he advocating that we start writing our test code inside the actual classes? Dear lord the mess!". Why would you test an Add method inside a class called Test inside an assembly with the name Tests. All in all, I think a more real world class would have proven a better example of what TUnit is trying to bring to the table, or maybe it would just have made it a bit less confusing to me as to what the big change to testing was/is. I found the documentation for TUnit, but their example was the same code you were showing so that didn't help.
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф 2 ай бұрын
Example is the same because probably it’s a paid ad ;)
@LukeAvedon
@LukeAvedon 2 ай бұрын
TestContext is such an awesome concept. And no reflection omg, omg omg. Going to buy your testing course. My favorite is still the G-G-G-G-G-Unit. Poppin tham thangs....
@nanvlad
@nanvlad 2 ай бұрын
Good library. Can you compare it wth a new xUnit v3? They also made a lot of changes, comparing to the v2
@vannwx
@vannwx 2 ай бұрын
This testing ordering sounds cool but it will lead to maintainance issue eventually. Tests should not depends on execution order.
@the-avid-engineer
@the-avid-engineer 2 ай бұрын
Not a fan of the assertions part at all but I do like the rest. Would prefer to use Shoudly for assertions and have sync or async tests at my own discretion rather than being forced to be async It would be interesting if a test could return something that could be passed to the next test.. but that’s probably too crazy
@Thomhurst
@Thomhurst 2 ай бұрын
Tests can retrieve other tests context objects. And you can store stuff in your contexts "ObjectBag" so that's possible!
@astralpowers
@astralpowers Ай бұрын
What's preventing me from using xUnit is the lack of parameterized test classes from NUnit. -It seems like TUnit does not have this.- It seems like you can. The same ArgumentsAttribute in the method can also be used in class constructors.
@nickchapsas
@nickchapsas Ай бұрын
xUnit has parameterized test classes
@astralpowers
@astralpowers Ай бұрын
@@nickchapsas so i can decorate a class with [InlineData(1)] [InlineData(2)] like I could in NUnit using [TestFixture(1)] [TestFixture(2)] and have the tests in a class run with different values in the constructor? Or maybe I'm calling this feature the wrong name. I've seen how people do this in xUnit, and you're supposed to write custom drivers to achieve this.
@chris-pee
@chris-pee 2 ай бұрын
"I don't think you understand how great that is of a thing" Well, you're right, I don't. Maybe it's just me, but I don't feel you've explained what's so great about TUnit. Also, since it's source generated, I expected a bit more. For example, the custom properties in TestContext is still a dictionary of objects, so you can't really have a strongly-typed configuration. But compile time errors for [Arguments] are nice.
@vasilyh4588
@vasilyh4588 Ай бұрын
Isn't *Async suffix is required for async function in notation?
@positronalpha
@positronalpha Ай бұрын
Required by whom? Nowadays it would make more sense to specify *Sync for the rare synchronous method :). In C#, specifying the return type in the name of a method is superfluous. Better to employ an analyzer to produce a warning in case a Task isn't awaited or assigned to a variable.
@vasilyh4588
@vasilyh4588 Ай бұрын
@@positronalpha It is definition of notation - so would be nice to have.
@ghaf222
@ghaf222 2 ай бұрын
I’m keen to know how people do versioning in .NET if they aren’t using CI/CD. I can’t find a way to do it that’s not manual. I had a way that worked in the project file using dates but that made Nuget packet manager behave strangely.
@pilotboba
@pilotboba 2 ай бұрын
You can use gitversion and run it in your build script. Which is basically how we do it in our CI which is nothing more than an automated way to run your build script. (just don't tell me you don't use version control either.)
@ghaf222
@ghaf222 2 ай бұрын
@@pilotboba Thanks, I’ll look into that.
@Zencoder720
@Zencoder720 2 ай бұрын
I'm also not really following the power of this tool over other frameworks. In my testing flow i wish there was a simple way to cache the dependencies between tests
@berry212
@berry212 2 ай бұрын
This opens up several windows where we had to create abominable structures. For flakiness, I had to develop a whole retry library... Does this support Specflow?
@Vosoo-e9r
@Vosoo-e9r Ай бұрын
what Editor are u using??? Looks like Visual Code but not this
@restveggie6155
@restveggie6155 Ай бұрын
JetBrains Rider
@Vosoo-e9r
@Vosoo-e9r Ай бұрын
@@restveggie6155 +++
@DustinDustin00
@DustinDustin00 2 ай бұрын
Man, I'm retired, but I know somebody is going to have to update thousands of my test cases to this.... once management prioritizes it. Can these be mixed so new tests use this and the old tests can be left in place?
@DotNetCookbook
@DotNetCookbook 2 ай бұрын
Really, most projects just need some library that can assert things and some framework that can run those assertions. I've never met a real-life scenario where unit-tests related reflection would be the bottleneck why unit tests run slowly. Also these days you might want to use a library that LLMs know about, so that you could autogenerate test cases sometimes. But that's about it, it's not that complicated.
@hlazunov
@hlazunov 23 күн бұрын
Does it compatible with AutoFixture?
@Cristian-ek7xy
@Cristian-ek7xy 2 ай бұрын
I'm happy with NUnit
@Maloooon
@Maloooon 2 ай бұрын
Yeah, I expected something really flashy. But aside from using the new test runner, it mostly feels like NUnit. Maybe it has a few more options for "Before", but otherwise, it feels the same.
@Domse65
@Domse65 2 ай бұрын
xunit is streets a head of nunit
@DemoBytom
@DemoBytom 2 ай бұрын
@@Maloooon The benefit of this new unit testing framework is that it's much faster than both nUnit and xUnit, and supports AoT, which is becoming a bigger and bigger thing in *some* use cases. For th eprojects I'm working on at work it probably wouldn't matter much, but I can see some that could really use those benefits.
@coloresfelices7
@coloresfelices7 2 ай бұрын
@@Domse65 Why do you think so?
@Domse65
@Domse65 2 ай бұрын
@@coloresfelices7 in my opinion assert syntax is weird, shared context is not great, and the way of writing setup and teardown is not as good as just a constructor and a dispose method. Xunit is just a lot less complecated and a lot more barebones and easy to use. Also in my experience xunit is a lot faster too
@fakhrulhilal
@fakhrulhilal 2 ай бұрын
Nice, it's closer to NUnit rather than XUnit. I like they put `Before(Test)` which is feature I miss from NUnit but not in XUnit. But, I have to await for assertion? Ok, time to get used to.
@markhenderson5283
@markhenderson5283 2 ай бұрын
I have mixed feelings. While I'm sold on supporting the new test platform, and source generation over reflection. The rest of the features I'm not sure are all good idea. Maybe, maybe not. I'm not passing judgment yet. I do wonder if xUnit could be updated to support test platform and source generation?
@Domse65
@Domse65 2 ай бұрын
I see the same problem with TUnit and NUnit, which is not present with XUnit, which is thats it's a lot easier to use and code tests quickly with resharper. With just base resharper if I decide some line in my code needs to be setup before the test just a quick keyboard shortcut and its automatically moved to the constructor. This make writing tests a lot faster and easier since you don't need to write boilerplate code by hand. Also XUnit assert syntax is a lot better in my opinion
@nickchapsas
@nickchapsas 2 ай бұрын
You can do the same thing in TUnit
@ibrahimhussain3248
@ibrahimhussain3248 2 ай бұрын
I like it. I hate tests being a different project
@derekmassey2377
@derekmassey2377 2 ай бұрын
I completely agree that Unit tests being in the same project as the class being tested would be a game changer. After digging into it a bit more I don't think that is how it works in TUnit. Much to my disappointment. It would be so much easier to write and refactor code if the test code didn't have to be in a separate project.
@Zullfix
@Zullfix 2 ай бұрын
Nick, would you consider making a video about required CET in .NET 9 and the 10-100% method calling performance regressions that come with it on any CPU that isn't a modern intel processor?
@nickchapsas
@nickchapsas 2 ай бұрын
Wait that’s a thing??
@ZlobnyiSerg
@ZlobnyiSerg 2 ай бұрын
Isn't test dependencies are kind of antipattern? Each test should highlight single problem and should be independent and self-sufficient? Also, the "Before" initializers are too implicit in several ways: first of all logic of initialization could be spread among test classes and be "surprising", and second - not very clear what parameters can be passed to "Before" attribute - no code completion with choices can be used. Performance is great btw.
@Thomhurst
@Thomhurst 2 ай бұрын
There's analyzers that tell you what parameters to pass to each before/after method. And sharing among multiple classes won't be a thing for before/after class, unless you use before every/after every. I tried to make the language obvious. If you use a normal before/after(class) it'll only affect tests in the class it's defined in
@Kotz_en
@Kotz_en 2 ай бұрын
Aren't tests that depend on other tests typically an anti-pattern? I don't see why I'd want to use the DependsOn attribute.
@Thomhurst
@Thomhurst 2 ай бұрын
Integration testing or where state matters. Less relevant for unit tests.
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф 2 ай бұрын
@@Thomhurstsharing state between test runs is pure evil
@LyndonVrooman
@LyndonVrooman 2 ай бұрын
Normally I agree with this, but, I've had a number of cases of end to end certification tests that require work to have been completed on a third party object in a previous test before it can run. Marking those as skipped or failed could save a few minutes per test run in cases were particular integrations are down.
@mynameisshadywhat
@mynameisshadywhat 2 ай бұрын
​​@@ВладиславДараган-ш3ф For unit tests yes. There are other types of testing where shared state can be crucial to testing the thing properly. Its subjective and all depends on what you're testing, how it was designed, what it's doing ,and the level of complexity. Saying that sharing state between any type of testing is pure evil just shows your inexperience. Looking at your previous comments on Nick's videos tells me you're the kind of person who doesn't work well on teams or existing products because you'd spend more time complaining about how bad it is than actually moving it forward.
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф 2 ай бұрын
@@mynameisshadywhat sharing state even in integration tests leads to fragile shitty code that yes, I will complain about lol. Saying that's OK and refusing to isolate tests is a skill issue.
@TedOnTheNet
@TedOnTheNet 2 ай бұрын
Seems they were heavily inspired by Specflow...
@davidghydeable
@davidghydeable 2 ай бұрын
I would like to see a video about Mocking frameworks now Moq has gone out of fashion. What is your approach to Mocking Nick?
@olivier0003
@olivier0003 2 ай бұрын
100k, you deserve it !
@regestea
@regestea 2 ай бұрын
I think it's better to add these futures to XUnit or NUnit instead of recreating a library or maybe a package for XUnit or NUnit to add these futures because most of us don't like to go for a new library
@dsvechnikov
@dsvechnikov 2 ай бұрын
I hope it will have better documentation than xUnit... I mean, I hope I wouldn't need to analyze library's source code to find all supported attributes and to understand what they do. That alone makes xUnit very hard to recommend
@ThugLifeModafocah
@ThugLifeModafocah 2 ай бұрын
I like they use NUnit style assertions because you can read like a human. Assert.That(something).IsEqual(thisOtherThing). Why programmers wants to read code when they can read english?
@JoonhwanLee
@JoonhwanLee Ай бұрын
Svelte to react is TUnit to X/NUnit
@0xSLN
@0xSLN 2 ай бұрын
Playwright?
@robrider838
@robrider838 2 ай бұрын
People still write tests? AI does mine for me and these tests have helped me catch many subtle bugs.
@modernkennnern
@modernkennnern 2 ай бұрын
Source generated test library 👀
@M0J0-RL236
@M0J0-RL236 2 ай бұрын
await in a test method for non async code is just odd
@marek19922209
@marek19922209 2 ай бұрын
Tests should not depends on each other
@ArnonDanon
@ArnonDanon 2 ай бұрын
Thanks for intreducing a new tool to our toolbelt, now we know it exists we can decide if and when it might solve us a problem. Cool library thanks.
@goodfight1749
@goodfight1749 2 ай бұрын
Man.. just used NUnit 😢
@fusedqyou
@fusedqyou 2 ай бұрын
Keep using it. TUnit will not exceed NUnit in a long time, and any experience you gain will be usable in TUnit just as much.
@nickchapsas
@nickchapsas 2 ай бұрын
Keep using it, TUnit is not ready yet
@juniorceccon
@juniorceccon 2 ай бұрын
It is ok to not be using every new thing all the time.
@G41headache
@G41headache 2 ай бұрын
There are far more important things than test frameworks, don't worry
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Nick Chapsas
Рет қаралды 101 М.
.NET Aspire is Finally Awesome in .NET 9
11:37
Nick Chapsas
Рет қаралды 23 М.
Why I'm Worried About Blazor and its Future
19:31
Nick Chapsas
Рет қаралды 40 М.
Stop Using FirstOrDefault in .NET! | Code Cop #021
12:54
Nick Chapsas
Рет қаралды 94 М.
Javascript inheritance mastery through prototyping!
16:48
Marko Code Academy
Рет қаралды 123
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 104 М.
The Only Type of Testing You Need
14:22
Nick Chapsas
Рет қаралды 40 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 643 М.
"You're Doing Validation Wrong in .NET" | Code Cop #023
14:44
Nick Chapsas
Рет қаралды 39 М.
Swagger is Gone in .NET 9! Replace It With This.
9:34
Nick Chapsas
Рет қаралды 77 М.
Front-end web development is changing, quickly
3:43
Fireship
Рет қаралды 1,3 МЛН
Stop Using Booleans in Your Code! | Code Cop #022
8:47
Nick Chapsas
Рет қаралды 58 М.