Spring Boot Testcontainers - Integration Testing made easy!

preview_player
Показать описание
In this tutorial you are going to learn how to write an integration test in Spring Boot using Testcontainers. We are going to use Testcontainers to spin up a PostgreSQL database in a container and use that for our tests. We will write a Repository test and a Controller test that calls the repository that talks to our database.

🔗Resources & Links mentioned in this video:

👋🏻Connect with me:

Рекомендации по теме
Комментарии
Автор

Thanks for sharing It’s gonna be helpful

saidoubarry
Автор

Dan, you are really an asset for whoever wants to learn spring in very easy way.

ssantosh.sarkar
Автор

🎉I like the style you show the stuff 🎉

morpheus
Автор

The best explanation on spring boot and integration tests with testcontainer. Your videos are so precious. Thank you so much

stefanoforgiarini
Автор

Thank you, a great and practical tutorial

milad_mo
Автор

Yes you are right, often due to time constraints we often skip writing test cases😅

maheshbabu
Автор

Great tutorial as already stated by most commenters. One thing though: Around 31 minutes in, your test fails because you now have 31 objects in your test data. You update the test to make the test pass. Might the reason the test fails in the first place be that the @Transactional and @Rollback does not work when inserting to the database via the RestTemplate? The Spring docs state that: "The Spring Framework does not support propagation of transaction contexts across remote calls, as high-end application servers do." Since this is a call onto the endpoint, not on the repository, this may be the cause of the error. Im all new to both Spring, Spring boot and Spring data jdbc and transactions, so I might very well be wrong.

johannesAkse-yhln
Автор

Dan where can someone get a spring t-shirt? 😢 I have looked everywhere…

vicariousgreek
Автор

Nice video and great explanation! I have one question: If I have so many test classes that share read/write resources, best approach is to decouple dependencies between them first? What about parallelism with multiple container instances? Thank you so much!

adriamanes
Автор

hey @dan!, great resources! I love the way you express the process :D Im also trying to follow best practices, and noted that you skip adding the public modifiers on method? are you following some specific convention that I can check out? or is just for tutorial simplicity and speed? thanks again for your time and effort!

Juanjse
Автор

Hey Dan, love the videos. Can we consider this still in the scope of Unit Tests? I have the impression this is actually a semi-Integration test

markkuuss
Автор

Great video again, Dan. Could you please add the link to the blog post you mentioned at the end of the video. Thank you so much.

birgitkratz
Автор

This video are awsome, better then Testcontainers doc, I'll immediatly start to follow you 😅

markswellmenezes
Автор

Hi Dan, thank you a lot for this video. Do you have any examples using Kafka with test containers?

hemerfyou
Автор

Just discovered your channel these past days, big gold mine! Keep it up and thanks for the help! I was wondering how you easily use the HTTP instead of curl command and the JSON being formatted.. I tried various packages but it did not work for me.

nechititudor
Автор

Thank you Dan for this useful video. It seems @Transactional and @Rollback don't work with servlet environment (client and server run in separate threads -> in separate transactions). I have used annotations @Order and @TestMethodOrder to set the order of tests' execution.

ninadan
Автор

Very great explanation till the last minute 👏🏼

About the last bit though:
When we're not specifying orders for our Unit Tests, it might run them in any order, right?
So when we're writing tests, they should pass independently and constantly (regardless of the order).
Now, when we're inserting a new post, then the vount would be 101. If it runs the count test first, it would be 100.
So, either a test on the count is not a good idea, or we should remove the recently added post right after testing insertion in the same test method.

hamidrezarezaei
Автор

In my case i could not get the Rollback annotation to roll back so as to remove the added post in the successful test case, which caused a failed count on the find all test case of 101 instead of 100.

stephaneislistening
Автор

Thanks for sharing! Very useful.

Is there a way to speed up the compile time ?
I'm using Mysql image for test containers.
I takes about a minute to compile before tests are running.

MrSurprise
Автор

Thanks for the great videos, as always.
One small thing: I guess your update test is not doing anything since you never called update endpoint. 😀

VLADICAKG