The Best Way To Use Docker For Integration Testing In .NET

The Best Way To Use Docker For Integration Testing In .NET

Milan Jovanović

10 месяцев назад

29,387 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Madhu Sameena
Madhu Sameena - 12.10.2023 21:37

Thank you for the cool content, This is is really interesting
I used SQLite or in memory for my API Tests so far, but this is nice.
It would be great, if you can release one video with calling APIs in tests and also apply the migrations to replicate the real scenario

Ответить
vincent benazet
vincent benazet - 22.09.2023 18:38

Great Video, I don't understand how you set up your database structure. Does it do it automatically through the DbContext configuration? If I have foundational data, can I use Entity Framework migrations, or do I need to generate an SQL script for that ?

Ответить
Sunny Patel
Sunny Patel - 21.09.2023 09:29

Great stuff Milan. Had one question is there a way to not use EFCore? I got a project that just uses SqlConnection which calls a store proc and in the settings I am passing only a connection string.

Ответить
Üsame Savas
Üsame Savas - 10.09.2023 15:44

Why don't you test against API endpoints instead of Service methods?

Ответить
Ali Esmaeili
Ali Esmaeili - 31.08.2023 00:04

Great and informative thanks

Ответить
muumitramm
muumitramm - 30.08.2023 11:07

Why should i use temporary database if i just could use Moq to mock the database. No need to spin up anything. :)

Ответить
Dev l!fe
Dev l!fe - 29.08.2023 16:25

Thanks for the amazing video.
Just a question, how about using an interface in API and then reference it to the test?
Something like :
public interface IMarker { }

Ответить
Ben Lewies
Ben Lewies - 29.08.2023 10:49

Great stuff, Milan. Why not use Selenium IDE for running your web tests (alongside Docker for setting up your infrastructure)?

Ответить
Conor Flannery
Conor Flannery - 29.08.2023 09:29

I think this is one of your most helpful videos yet Milan. Given that once you've done the boilerplate to set this up, it's actually pretty easy to write additional tests, would you say this is a good substitute for unit tests as you don't need to mock anything? Or would you still use unit tests alongside this method?

Ответить
Nnaemeka Eziamaka
Nnaemeka Eziamaka - 26.08.2023 00:17

Beautiful! Just Beautiful!

Ответить
Damian Nizio
Damian Nizio - 22.08.2023 15:08

How would you properly implement WebAppFactory is you have several Database contexts?

Ответить
TheSpicyCoder
TheSpicyCoder - 22.08.2023 07:05

Great Video.
When you perform Build & Test inside Docker containers, using test containers might not work.
As Integration tests are already being executed within a container & you want to spin up a container within a container.
Any workarounds?

Thanks

Ответить
Palash Choudhary
Palash Choudhary - 20.08.2023 04:54

Man... I got so many comments saying you should use count 1.... Thanks for clearing the doubts.

Ответить
Viktor Zafirovski
Viktor Zafirovski - 17.08.2023 16:21

Excellent Video! 'm using TestContainers on multiple services, but I don't know why on MSSQL TestBuilder there is no WithDatabase() method. I tried to specify the Database name with WithEnvironment(), but nothing changed. I checked the Connection String with the debugger, the breaking point set on a variable, and also with the SSMS, I was connected and the necessary database is not there. I made a function for building the Connection String and it works, but it's a little weird when I made a pull request and one of the services I'm testing on GitHub Actions is in progress the whole day. The yellow circle just spins in place 😄🙃 I don't know why. 🙂 The others finished successfully for more than 1 min. On my machine, all test works fine. Thanks for the video.

Ответить
Anh Nguyen
Anh Nguyen - 17.08.2023 12:41

Finally this day has come! I know once day you will touch this topic. I'm applying this topic on both my side and main projects.

Ответить
Anders Christiansen
Anders Christiansen - 17.08.2023 00:22

How does this work without running the migrations on the docker database?

Ответить
Vedran Mandić
Vedran Mandić - 16.08.2023 10:38

Milan, excellent video, I am just working on this setup so video came in perfect time. I missed one thing. I guess the SQL service in the container pings back when its actually started and that signals the StartAsync to have a successful result? Also, I guess, you do DB migrations up in your Program/Startup logic when the factory goes through. I am asking as I need to do exactly this, migrate up a new instance of DB schema at one point and I guess its is OK in StartAsync after container is spinning? Ideas? Thx!

Ответить
Ernest Fakudze
Ernest Fakudze - 16.08.2023 04:04

Thanks very much for this. I've always struggled with Integration Testing and this clarified it for me.

Ответить
Вкидимир Подгубенский
Вкидимир Подгубенский - 15.08.2023 21:16

These tests also need something like Respawner library to clear containers db after test execution. Thanks to it a collection of tests can use one container.

Ответить