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

preview_player
Показать описание

Integration testing is a testing approach that tests the integration between multiple components. Usually, this will involve a database, so you can test your query logic. Docker is an excellent tool for creating throwaway databases for your integration tests. And you can make it even better with the Testconatiners library. It allows you to programmatically create your docker containers for integration testing.

Testcontainers - Integration Testing Using Docker In .NET

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters:
0:00 Creating the test project and installing Testcontainers
1:55 Implementing a custom WebApplicationFactory
6:11 Adding a PostgreSQL container with Testcontainers
8:15 Creating the base integration test class
9:57 Integration test 1: Creating a product with exception
13:10 Integration test 2: Creating a product and validating in the database
16:13 Integration test 3: Getting a product by the ID
Рекомендации по теме
Комментарии
Автор

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.

ndanh
Автор

Dude, if you ever wrote a book, I got first dibs on it. 😊

eja
Автор

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

palashchoudhary
Автор

This is a great topic! I haven’t finished the video but the one improvement I’d add is to not have credentials hard-coded in the source. Showing the noobs the correct way to implement that would give them a head start on being a better dev that thinks about security.

watchchat
Автор

Hey, thanks, nice video. Would be also nice to have explainations concerning integration tests in deployed DEV and STAGING environments using CI. Thanks for the job done ;)

julienlefevre
Автор

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

ernestmfakudze
Автор

About time you do this type of video, you need to do more docker work!

nove
Автор

This is a great resource and had really helped with integration testing. Thank you for your work covering this topic/technology!

darylbeaumont
Автор

Just came across a few videos of yours regarding testing. Would love if you done more, maybe a dedicated playlist.

I see many people talk about integration test for web API’s. But haven’t seen much on integration testing for asynchronous apps (messaging, Kafka etc). Or web apps (ui) - apart from e2e…using web application factory could be useful here also.

daauggy
Автор

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

madhu-sameena
Автор

Very good thank you. I like the explication about the program class at the beginning. Kind of not necessary but making everything super clear

porcinetdu
Автор

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?

Flanno
Автор

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

gentdpc
Автор

do you have an example video of how to do the DbUp portion of the database? I mean, when it spins up the postgres container, does your image already exist with the schema or is it dynamically running your scripts?

ross-owen
Автор

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 { }

devlife
Автор

Great video Milan!
One thing bothers me as I see shadowing methods as a huge red flag and problem causer.
I'm just thinking that explicit interface implementation would be much better here. and if not, then why not to override DisposeAsync with line you've put and call to base implementation?

wojtas
Автор

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

benlewies
Автор

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.

bxerzxu
Автор

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.

sunnypatel
Автор

Thanks for the content.

I have a question : what are the Pros and Cons when using TestContainer over the WireMock ?

TrungTran-leht