Spring Boot 3 Integration Testing With TestContainers | Junit 5 | JavaTechie
Vložit
- čas přidán 21. 08. 2024
- #JavaTechie #SpringBoot #IntegrationTest #Testcontainers
In this tutorial, we will discuss how to do Spring Boot application Integration Testing using Testcontainers , same as production environment
👉 Simple Integration Test using MySQL DB
👉 Problem with above approch
👉 Solution:
Step by Step guides to perform Integration Test using Testcontainers
Spring boot microservice Premium course lunched with 70% off 🚀 🚀
Hurry-up & Register today itself!
COURSE LINK : javatechie5246...
PROMO CODE : JAVATECHIE50
OR use Javatechie APP
Download the JavaTechie app on your iOS or Android device from the App Store or Google Play Store.
Find the links below :
Android 🌐 : play.google.co...
IOS 🌐 : apps.apple.com...
GitHub:
github.com/Jav...
Blogs:
github.com/Jav...
Facebook:
/ javatechie
Join this channel to get access to perks:
www.youtube.co...
Techies if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community ,
you are free to use source code from above mentioned GitHub account - Věda a technologie
“Manager will dance on top of your head” - quite funny. But on a serious note, thank you for all your work on this.
Solved a critical user story today in my company watching your videos on spring batch processing. Thanks a lot for your hard work :)
Glad to hear this 😊. Keep learning 👍
This channel is making me a better java developer everyday, kudos to you Sir.
Thanks buddy 😊. Keep learning
I started reading the documentation, but was a little confused. So, I just opened youtube searched for 'testcontainers javatechie', learnt about the concept in an easier way. Now I can start coding. Thank you very much for all the great effort you are putting in bro! You are helping a whole community.
Thank you so much buddy . Keep learning
Appreciate your efforts, Basant. God bless you. 🙂
God bless you for making these videos you made me better at what I really wanted to do!!
This is a very commendable effort !! You are an inspiration to java developers like me, Sir. Kudos to you !!
Sir this video is circulating in my company as official reference for updating test traditional test case.
Thanks for the good content man. appreciate it
From which SpringBoot version can I use the "test containers"? Very good channel, greetings from Argentina!
Thank you
Very Helpful bro😍😍
Excellent work!. I am curious to know, how to check the inserted data in test containers.
Yes you can just inject @CourseRepository and call findAll() method and log it
Thanks, it really helped.
One query : Can we see the test data in test sql db?
❤❤
Yes you can just inject @CourseRepository and call findAll() method and log it
Super sir ❤
thank you so so much Sir !
You don't have to start and stop the container yourself, this is already done by the @Testcontainers annotation.
Yes agree 👍
Thank you for the great video!
Can you please make a tutorial on testing a spring boot 3 application that has security enabled (Keycloak). Assuming that we do not want to disable the security while running unit tests (being able to test the controller) and integration tests (using keycloak testcontainer). The application can have @EnableMethodSecurity and we also use @PreAuthorize("hasRole('user')") above the controller methods to have more granular control. What is the proper way to test a secured Spring Boot 3 application? Maybe during the actual tests we should generate an actual token and then try to test the endpoints.
Thank you in advance!
Great vid. Could you also make a video on functional testing with cucumber? Not many videos on this out there.
Here it is buddy i already did it a few yr back czcams.com/video/8AEQt4CSX5U/video.html
Make one video about CORS configuration
Sure i will do that
So, this kind of testing is possible only if we're using docker in projects, incase if we're not using docker tools or any other tools in our projects, then ultimately we have to do regular integration testing only right
Correct
Thank you so much. Do you have a linkedin I would like to tag you
I haven't created a LinkedIn profile for my channel but yes You can find my LinkedIn with "Basant Hota"
Hi good job. Please we can use directly H2 database?
Is it necessary to explicitly stop the containers?
No it's optional
Is it possible to mock atleast the 3rd party API calls.
Let's say my service calls an external HTTP API, can I mock that, because that may not be up, and may be I don't want to pass the real credentials
To run TestContainers, do we have to install Docker in our local machine ?
Yes without docker how can we run the container
Thanks for this nice Integration Testing. please can you explain me what is this method doing: private String asJsonString(Object object) {
try {
return new ObjectMapper().writeValueAsString(object);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
I am new in Integration Testing. Thks
This method simply converts objects to json string
thanks@@Javatechie
Its awesome ...thanks much.
When we are running tests locally...we can start docker..not an issue but when we are running in cicd..how can i setup and start docker before running tests there??
I has the same question in mind. But when I pushed to github. My CICD github actions was able to run the integration just like in local. The test containers config itself will setup the database in the pipeline.
@@abulsyed4851 thanks. You mean there is no need of docker setup?? Can u plz share the code file and project of possible...will be really helpful
@@arvindimage yeah that's correct. I didn't have to setup anything in my GitHub actions, other than java.
Great tutorial. However this does not work in pipeline as we cannot run docker in docker on gitlab. How can we start testcontainer as a service in gitlab and then run the test there?
What pipeline are you using
we want testcontainers with webflux
Okay will do that
@@Javatechie Thank you very much. Appreciate if you can deliver the video fast. there are not much resources about that.