Clean mocking for unit tests using NSubstitute in .NET (Core, Framework, Standard)

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 47

  • @nickchapsas
    @nickchapsas  3 роки тому +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

    • @jebarcha
      @jebarcha 2 роки тому

      can you share a disccount code may I ask? Thanks.

  • @digitalfriday
    @digitalfriday 4 роки тому +12

    Excellent introduction to NSubstitue! Not only are your explanations pedagogical, but you also communicate clear and concise intent & flow of information with your code - clear code which speaks for itself. Well done.

  • @sulton-max
    @sulton-max Рік тому +2

    I'm just amazed from clear syntax of NSubstitute. Thanks for the video

  • @payamism
    @payamism Рік тому +1

    20 minutes of great training. No fluff, no BS, just enough to solve my problem.

  • @maxbeber
    @maxbeber 4 роки тому +4

    Totally agree that the code looks very clean. I have just started a new project and I am considering to rewrite all my tests using NSubstituite. Keep it up the good job!

  • @janoslaszlo3272
    @janoslaszlo3272 4 роки тому

    Very nice mocking framework. I'm going to try it and probably use it from now on.

  • @CutieHoney
    @CutieHoney Рік тому

    Wow, your presentation has changed so much since you did this video. Still, very informational in light of current events.

  • @nothingisreal6345
    @nothingisreal6345 3 роки тому +3

    great intro in the framework. But I can't help myself: what most unit test demos show is, that the 1.) the compiler and the framework works 2.) the author can duplicate the behavior in its code into a unit test or the other way around. I would only test stuff that is really of interest. In this case the most important test would be that calling the hand crafted SQL code (which can not be verified at compile time) at least executes and that it executes with a reasonable performance. Unit tests and test driven development should be performed, if only for the reason, that it makes testing new code SO much more efficient. But I can see those management slides that show that we have 10.000 unit test with 1.000.000 lines of code - which suggest the quality has to be great. But it actually doesn't. The tests need to go to the interesting parts and not just consist of a bloat of trivial stuff.

    • @StrandedKnight84
      @StrandedKnight84 Рік тому

      Totally agree. You should test major behaviors, not minor implementation details. The tests shown in the video are basically useless. But they serve as a demo of the framework, which was the intention here of course.

  • @giridharamadhavan2200
    @giridharamadhavan2200 3 роки тому

    This is awesome! Thank you for a great video on Nsubstitute and mocking

  • @fifty-plus
    @fifty-plus Рік тому

    AutoSubstitution with Theories makes testing so much nicer.

  • @ivogluhchev
    @ivogluhchev Рік тому

    I'm new to NSubstitue (coming from Moq), the basic concepts are very well explained, congrats. But I would like you to share your approach on mocking HttpClient because as far as I found out this is not a straight forward process. Thanks for the video.

  • @habanerohoncho
    @habanerohoncho 4 роки тому

    Thank you, Sir! Clear, concise and well explained.

  • @luisgabrielmenaarnedo7854
    @luisgabrielmenaarnedo7854 2 роки тому +1

    Hey mate, great video.
    You should've explained all the CRUD process, not just the read, that would've been awesome mate.
    Could you please make a video explaining how to mock the Create and delete process?

  • @anouartouati2561
    @anouartouati2561 3 роки тому

    Excellent video, Thank You.

  • @hmmer3471
    @hmmer3471 4 роки тому

    This is useful, I will try it tomorrow

  • @themistokliskafentzis9981
    @themistokliskafentzis9981 4 роки тому +2

    Nice job Nick, I am wondering how to unit-test transactions in Entity Framework Core with NSubstitute or Moq when I am trying to unit-test a method that include code with _context.BeginTranscnction( ) ?

  • @douglasproglima
    @douglasproglima Рік тому

    How to test protected methods?

  • @divyap9698
    @divyap9698 Рік тому

    Hi ....is there any way to mock a static method without writing a wrapper or changing the code flow?

  • @durgaramana9428
    @durgaramana9428 4 роки тому +1

    Is it possible for data access methods in ado.net

  • @AkshayaTupe-u3l
    @AkshayaTupe-u3l Рік тому

    Can we used the solution for NUnit?

  • @alveiroceron
    @alveiroceron 2 роки тому

    What should do I if I have extension methods (third party library) inside a method that I want to test?

  • @ivandrofly
    @ivandrofly 2 роки тому

    Hello, you recently reply to my comment about the triple a's.
    I manage to create a snipped but when I insert the snipped, the first line is formatted correctly but the "// act" and "//Assert" are inserted at beginning of the line, in other word these lines doesn't get formatted.

  • @sunkanmiijatuyi8118
    @sunkanmiijatuyi8118 4 роки тому

    @Nick Is there a way to test a public access modifier method that has a private access modifier method or static method inside itself?

  • @djidjohoc.agboton7515
    @djidjohoc.agboton7515 3 роки тому

    Hi, do you have any sample using Nsubstitute in VB.NET? Thanks for sharing. Best regards!

  • @mohamedelbasmy5160
    @mohamedelbasmy5160 4 роки тому

    GREAT VIDEO. THANK YOU SO MUCH !!

  • @alfonsobarona
    @alfonsobarona 4 роки тому

    Great video! One question: how would you pass the Nsubstitute dependencies to your system under test if the SUT were to be instantiated using IClassFixture for parallelization of the test execution?

  • @arthurmolinari3262
    @arthurmolinari3262 3 роки тому

    Awesome video.

  • @JavierLoudermill-q7m
    @JavierLoudermill-q7m 2 місяці тому

    Margarita Overpass

  • @serhiihorun6298
    @serhiihorun6298 4 роки тому

    Thanks again!

  • @balaji-r-93
    @balaji-r-93 3 роки тому

    Hey Nick, Thank you so much for these videos. You really make developers better and more efficient. I have a question on this, Will NSubstitute work with a Refit Interface which doesn't have an in house implementation? Could you clarify on that? I am breaking my head unit testing Refit interfaces with Moq and it doesn't work for me. Thanks in advance!

    • @nickchapsas
      @nickchapsas  3 роки тому +1

      It would yes. I use Refit with NSubstitude and it works like any other interface.

    • @balaji-r-93
      @balaji-r-93 3 роки тому

      @@nickchapsas Awesome, thank you!

  • @idgafa
    @idgafa 4 роки тому +2

    Prediction: next video is about FluentAssertion :)

    • @nickchapsas
      @nickchapsas  4 роки тому +1

      I don’t know if it’s gonna be the next one because I wanna cover FakeItEasy as well but it will probably be the one after the mocking ones

  • @ashishkumar6084
    @ashishkumar6084 3 роки тому

    How can we get the source code ?? I desparatly need it.

    • @nickchapsas
      @nickchapsas  3 роки тому

      The source code is available to my Patreons

  • @sunilanthony17
    @sunilanthony17 4 роки тому

    Nick, did you upload this project to GitHub yet? Trying to look for it but can't find it.

    • @nickchapsas
      @nickchapsas  4 роки тому +1

      Hey, it is uploaded under NugetPackageTutorials/MockingTutorial/CustomersApi.NSubstitute/

    • @sunilanthony17
      @sunilanthony17 4 роки тому

      @@nickchapsas Thank you. I've always had a QA team test my application. Now I'm trying to wrap my head around writing Unit Testing but I can't seem to understand testing DB CRUD operation. I understand to test my application algorithm but testing DB CRUD operation just confuses me.

  • @Ram92026z
    @Ram92026z Рік тому

    Man, I was waiting for you to write the test case for Create which you skipped.

  • @Layarion
    @Layarion 4 роки тому

    came here hoping to learn how to use Returns on a void method.

  • @trongphan6197
    @trongphan6197 4 роки тому

    hi looking for this source code in invited source

    • @nickchapsas
      @nickchapsas  4 роки тому

      It is under NugetPackageTutorials/MockingTutorial/CustomersApi.NSubstitute/

    • @sanjeevbr4676
      @sanjeevbr4676 3 роки тому

      @@nickchapsas I'm sorry I'm new to your channel, Where do I find this path which you have mentioned above?

  • @serhiihorun6298
    @serhiihorun6298 4 роки тому

    Thank u