C# Unit Testing Best Practices for Great Code Coverage

Sdílet
Vložit
  • čas přidán 11. 09. 2024

Komentáře • 37

  • @MilanJovanovicTech
    @MilanJovanovicTech  Před 10 měsíci +6

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @alexmbr
    @alexmbr Před 10 měsíci +7

    I also starting using NSubstitute because of the that controversy. I have to say, that now, I even prefer it over Moq.

  • @joehernandez3231
    @joehernandez3231 Před 10 měsíci +2

    Very informative, thank you.
    I had not heard about the Moq controversy, so thanks also for pointing that out. It does seem to have caused damage to the library's reputation because of the silent implementation.

  • @simongeering
    @simongeering Před 10 měsíci +1

    When retrofitting tests on existing code as shown, rather than doing TDD, it's always handy to deliberately break the code under test after you get each test passing. In this case by removing the return in the branch your presuming is being hit, to verify that your test is actually testing the code you think it is.

    • @simongeering
      @simongeering Před 10 měsíci

      Here you have unique errors for each scenario and they are used once in the code, this good design helps reduce the need for my above suggestion but in a general sense it's still a good way to double-check your tests.

    • @simongeering
      @simongeering Před 10 měsíci

      Ah you touched on it later in the video in passing when verifying the repo. 😊

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 10 měsíci +1

      A nice summary of the video through this short thread 😁

  • @enricoroselino7557
    @enricoroselino7557 Před 8 měsíci +2

    bro is showing facts 👑

  • @omerkulahli3865
    @omerkulahli3865 Před 10 měsíci +2

    it is very useful video, thank you Milan

  • @kasunjalitha2300
    @kasunjalitha2300 Před 10 měsíci +2

    Hi Milan, What do you think about using ASP NET Identity with Clean Architecture rich domain models? Or Its better to implement our own authentication workflow without ASP NET Identity in clean architecture?

  • @MrWTFNETWORK
    @MrWTFNETWORK Před 9 měsíci +1

    Why are you doing the last test verifying if the repository inserted the follower, checking if the method of the repo was called?
    Seems like you are getting coupled to the implementation of the method.
    Couldn't you make the follow method return the Followed entity instead and assert instead that the entity has the expected properties?

  • @noname-mh1zv
    @noname-mh1zv Před 9 měsíci

    Awesome video!

  • @HernanZbucki
    @HernanZbucki Před 10 měsíci +1

    Which Reault class are you using Milan?

  • @jesusdicent2
    @jesusdicent2 Před 10 měsíci

    Thanks

  • @xavAk
    @xavAk Před 9 měsíci

    Amazing video!
    What do you think about specflow ?
    Where we define the BDD and create functions for the tests

  • @weluvmusicz
    @weluvmusicz Před 10 měsíci

    What about testing that an insertion with EF Core made the correct database entry? And a step further, what about checking this on a real (testing) database?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 10 měsíci

      Falls under integration testing: czcams.com/video/tj5ZCtvgXKY/video.html

  • @quicoll14
    @quicoll14 Před 9 měsíci

    These tests from my point of view are fragile. If you refactor at some point your repository interface you will be breaking them, why not testing it like the user would use your api? Just instantiate your webapplicationfactory and send requests to it. Also, the use of the builder pattern is useful for creating entities/value objects. You could avoid having at the top of your test class some useless private readonly fields.
    I hope this helps you, and thanks for the video 🙂

    • @MilanJovanovicTech
      @MilanJovanovicTech  Před 9 měsíci

      Do you only write functional-style tests like that?

    • @quicoll14
      @quicoll14 Před 8 měsíci

      @@MilanJovanovicTech No. I also write unit tests, but mainly I run them for the domain layer + parts of a feature that cannot be tested through functional tests

  • @user-fe1ee4gt8g
    @user-fe1ee4gt8g Před 10 měsíci

    How about in VSA?

  • @techpc5453
    @techpc5453 Před 9 měsíci +1