Stop Mocking Your Database! Use Testcontainers in .NET

Поделиться
HTML-код
  • Опубликовано: 2 янв 2025

Комментарии • 44

  • @MilanJovanovicTech
    @MilanJovanovicTech  2 дня назад +1

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

  • @dotnetMasterCSharp
    @dotnetMasterCSharp 2 дня назад +2

    This is a great method for testing when adding additional logic to projects in production.
    Thanks, Milan, keep up the good work.

  • @antonmartyniuk
    @antonmartyniuk День назад +1

    Respawn library is a great addition to Integration Tests for intelligent database cleanup after running each test

  • @СергейИванченков-ДляСвоих

    Docker Desktop is not free for business environment, and installing Docker runtime alone outside of Destop is a hack that many would hate to follow through. It ain't as convenient as may seem. Starting Docker containers is slow as heck. However, there is much better way using Docker DB image, and that is create your own with all the schema and all data already created and then merely start that image instead of applying migrations every time you run tests. There is another inconvenience in updating dB Docker image when new schema changes are needed. It all depends on usage context.

    • @joaogabrielv.m328
      @joaogabrielv.m328 2 дня назад

      Docker is slow on Windows and macOS due to been a virtual machine per se. A free alternative for commercial usage is "Rancher desktop", That's what I'm using in my current job

    • @andersborum9267
      @andersborum9267 2 дня назад

      As you mentioned, a custom image may be appropriate if and when your schema has stabilized significantly as it adds significant overhead.

    • @ximonx
      @ximonx 2 дня назад

      Podman is an option 👍

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 дня назад +1

      There are other ways to run containers. Might be a good topic to explore in this year's videos

    • @MikeZadik
      @MikeZadik Час назад +1

      podman is fine.
      Respawner is also intersting. With testcontainer and respawner i got integrationstest to take less than 100 ms, which is okay. Creating a new container for each test seems excessive.

  • @joaogabrielv.m328
    @joaogabrielv.m328 2 дня назад +2

    What a way to finish 2024. Happy new year, Milan :)

  • @serb1146
    @serb1146 52 минуты назад

    Hi Milan, thanks for sharing, and keep me informed with new tech and approaches. I have hundreds of int tests in my project and they "sometimes" impact to each other, because of shared data. Example: test checks that all active documents are been deleted, but asynchronously another test running is creating active document same time for its case. Any idea how to handle that? Tests are created by the team continuesly.

  • @ahmadalsader1047
    @ahmadalsader1047 4 часа назад

    in Development , how to use Docker with DBUP to seed data ?

  • @coolY2k
    @coolY2k 2 дня назад +4

    The only problem is that it takes some time to initialize the Docker, especially for some databases.

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 дня назад +1

      We can mitigate this (somewhat) with an ICollectionFixture - only create one database container and use it for all tests. This will require more careful test cleanup.

    • @rodjenihm
      @rodjenihm 2 дня назад +3

      @@MilanJovanovicTech Isn't it possible to just run every test in transaction that rolls back automatically in the end?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 дня назад

      @@rodjenihm Technically, yes. Haven't used that approach in practice. Any caveats you've encountered?

    • @coolY2k
      @coolY2k 2 дня назад

      @@MilanJovanovicTech, some docker images, such as the CosmosDb Emulator, are slow even for that. ICollectionFixture is a good solution for some cases, but the problem is parallel running and commands.

    • @coolY2k
      @coolY2k 2 дня назад

      @@rodjenihm No, it's not possible by definition. If you have a transaction in ACID-style DB, it has to be finished entirely before anything can read or modify that data.

  • @adrianaagudolima6235
    @adrianaagudolima6235 2 дня назад +1

    Hello, how are you? Your videos are great and provide good tips for improving your skills. I saw that you uploaded a video with the audio track feature. You could continue uploading it with this feature. It makes it even easier to absorb content in my native language and learn more and more. Thank you, and have a great New Year.

  • @nikhilbalkhande2348
    @nikhilbalkhande2348 2 дня назад +1

    Your videos are great, but they feel a bit scattered. Could you please create a playlist to organize them in one place? This would make it easier to find and watch videos meaningfully.

  • @checox1909
    @checox1909 День назад

    Where could I find this sample project???

  • @sanzandsanz
    @sanzandsanz День назад

    Awesome video. Heap Thanks. How can I access the code for this project so that I can test it locally to play with it? Can you share the code please ?

  • @ellertfinnbogi
    @ellertfinnbogi День назад

    Where is the link for the source code for this?

  • @leonguerrero1745
    @leonguerrero1745 2 дня назад

    Excellent video!

  • @tiagosantos2136
    @tiagosantos2136 2 дня назад +1

    I don't know why microsoft want to go for a way different of the other languages with a specific way to run docker container. I really don't understand why this is a better solution than a docker-compose file...

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 дня назад

      Well you can technically also docker-compose for tests - but you'd have to run it manually before running the tests. Also you have to set up the connection strings yourself, etc.

  • @xelacanario
    @xelacanario 2 дня назад

    Thanks Milan, its great!
    Can you enable RUclips IA audio translation?

  • @10Totti
    @10Totti 2 дня назад

    Happy new year!
    But audio track ?

  • @tscher05
    @tscher05 2 дня назад

    While testcontainer tests can be useful, you can continue mocking your database (the secondary adapter). Testcontainer tests still are too slow compared to tests inmmemory.