The Best Way To Write Parameterized Tests In .NET Using xUnit

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 44

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

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

  • @rmsoft
    @rmsoft Рік тому +3

    Good, clear and simple.

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

    Thanks Malin, Keep up the good work.

  • @dotnetMasterCSharp
    @dotnetMasterCSharp Місяць тому

    absolutely awesome and useful,
    thank you Milan

  • @pilotboba
    @pilotboba Рік тому +8

    Very nice. I mostly use Inlinedata, but knowing the others is nice. I think also with the class you could data drive the test by pulling the data from a file.
    Small nit on your naming I use a very similar format but I think putting _Should_ in every test name is redundant.
    Instead of
    Create_Should_ReturnNull_WhenValueIsNull()
    I would use
    Create_ReturnsNull_WhenValueIsNull()
    Keep up the great videos.

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

    Thank you, great content as always

  • @NoName-1337
    @NoName-1337 Рік тому +1

    I love your videos. Thank you. Keep going.

  • @nove1398
    @nove1398 Рік тому +2

    Great share!

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

    Nice topic! 🙌

  • @hadmos855
    @hadmos855 4 місяці тому

    1:08 how do you delete the entire using block like that?

  • @Trump-N-Putin
    @Trump-N-Putin Рік тому +1

    Smashed that 👍

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

    Quick question, I noticed when switching over to using ClassData the values used are no longer showing in the VS Test Explorer like they would for InlineData. Do you know of a way for it to show?

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

      I'm not sure there is, but it doesn't really matter to me. The test cases are still there in the report and they're executed just fine.

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

      ​@@MilanJovanovicTechfigured it out, any data object you're using you have to use IXunitSerializable on it and tell xunit what the value types you're trying to use. We added a simple auto serialization helper class to handle this. Great video btw, never used Class Data until now, super clean!

  • @sunnypatel1045
    @sunnypatel1045 Рік тому +2

    great video! I would use Autofixture with customizations

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      Haven't tried it, will look into Autofixture

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

      @@MilanJovanovicTech ua-cam.com/video/ivEke62spOg/v-deo.html

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

      @@MilanJovanovicTech Autofixture and Bogus are great for generating data/objects for tests.

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

    Love your videos, in the future you can make one about preventing multiple logged users in a application? a hug from brazil

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

      How is that practical? 🤔

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

      @@MilanJovanovicTech
      Recently there was a security test at my company and the test pointed out that it is possible to log in with the same user at the same time, I use identity to manage users and I would like to know how to prevent more than one person from being able to log in with the same account at the same time

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

    What do you use to record your screen

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

    Great channel and coverage on architecture. :)
    I have a question, which may lead you to new content ideas! If an application has multiple contexts would you still use the repository & unit of work patterns?
    For example, an application has 2 databases both with Product tables where data will be read from both and persisted in many Handlers.
    Having two UnitOfWork objects seems to defeat the purpose of the UnitOfWork pattern? What are your thoughts?

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

      The question is why it has multiple contexts?
      - Different DBs -> Can't do transactions, since they won't work
      - Logical splitting -> Transactions are fine, but be warry of coupling
      If they are indeed logically separate, it still makes sense to have two UnitOfWork abstractions. But you don't want to ever mix these together. So only work with one DbContext at a time.

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

      Another comparable situation is when your application support two or several types of providers, for example MSSql and SQLite, dependent on your users' preferences. In this case you may end up duplicating or multiplying all tests if the "Arrange" part is not parameterized.

  • @29Aios
    @29Aios Рік тому +3

    Feed your Sku to the ChatGPT and ask to write unit tests with Moq, xUnit and FluentAssertions, you will be surprised. If not - ask it to use Theory instead of Fact.

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

      Note, however, that mocking is about bevahior, not data.

    • @29Aios
      @29Aios Рік тому

      @@krccmsitp2884 Hmm, why not use data passing to mock behavior ?
      PS. Actually he uses static methods in the sku, and it have to be rewritten to interface and instance methods to mock it properly, but it can easily be rewritten just by asking ChatGPT. Also it uses Factory template, but would be created by the DI.

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

      What happens?

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

    when to use xunit and when nunit?