Spring Boot Testcontainers - Integration Testing made easy!

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 76

  • @ssantosh.sarkar
    @ssantosh.sarkar 8 หลายเดือนก่อน +8

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

  • @thilaks3895
    @thilaks3895 2 หลายเดือนก่อน +1

    That was a fantastic video! It's been extremely helpful in understanding integration testing. I'd love to see a video specifically focused on best practices for integration testing in production environments. This would be a great resource for beginners like myself.

  • @stefanoforgiarini339
    @stefanoforgiarini339 6 หลายเดือนก่อน

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

  • @maheshbabu5400
    @maheshbabu5400 ปีที่แล้ว +6

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

    • @DanVega
      @DanVega  ปีที่แล้ว +2

      Right!

    • @IvanRandomDude
      @IvanRandomDude ปีที่แล้ว +6

      Yeah. So called TDD - Testless Driven Development

  • @rupeshpatil6957
    @rupeshpatil6957 4 หลายเดือนก่อน

    Good explanation. Thanks Dan

  • @saidoubarry4455
    @saidoubarry4455 3 หลายเดือนก่อน

    Thanks for sharing It’s gonna be helpful

  • @markswellmenezes1854
    @markswellmenezes1854 7 หลายเดือนก่อน

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

  • @vicariousgreek5711
    @vicariousgreek5711 ปีที่แล้ว +8

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

  • @morpheus4564
    @morpheus4564 ปีที่แล้ว

    🎉I like the style you show the stuff 🎉

  • @geekwithabs
    @geekwithabs 5 หลายเดือนก่อน

    Loved the video. Thank you!

  • @manoelcamposdev
    @manoelcamposdev ปีที่แล้ว

    Great tutorial. Thanks for that.

  • @ninadan2204
    @ninadan2204 11 หลายเดือนก่อน +1

    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.

  • @milad_mo
    @milad_mo 7 หลายเดือนก่อน

    Thank you, a great and practical tutorial

  • @FalcoCorragioso
    @FalcoCorragioso 11 หลายเดือนก่อน +2

    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.

    • @DanVega
      @DanVega  11 หลายเดือนก่อน

      It should not take that long. I have used MySQL / PostgreSQL and it takes seconds. It might help to turn on more logging and see if you notice anything strange going on.

  • @adriamanes
    @adriamanes ปีที่แล้ว +1

    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!

  • @hemerfyou
    @hemerfyou 10 หลายเดือนก่อน

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

  • @emileastih9006
    @emileastih9006 10 หลายเดือนก่อน

    Great video thanks 👍

  • @johannesAkse-yh9ln
    @johannesAkse-yh9ln 5 หลายเดือนก่อน +2

    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.

    • @sohaibelbokhari8319
      @sohaibelbokhari8319 5 หลายเดือนก่อน

      That's exactly what I noticed; the rollback is not considered when we perform HTTP calls during test execution

  • @danielmachadovasconcelos877
    @danielmachadovasconcelos877 ปีที่แล้ว +3

    What are the tradeoffs of using it rather than the docker-compose file with the new docker-compose support of spring boot?
    Doesn’t it seems you now have two places where you configure your infrastructure? 🤔
    One in the docker compose yml file and another with the testcontainer Java code. 😢
    Great videos by the way! 😊

    • @DanVega
      @DanVega  ปีที่แล้ว +4

      The docker compose is used for development. When you run a test you don't have access to that.

  • @Sucheit
    @Sucheit 10 หลายเดือนก่อน

    so easy, unbelievable

  • @markkuuss
    @markkuuss 11 หลายเดือนก่อน

    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

  • @birgitkratz904
    @birgitkratz904 ปีที่แล้ว

    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.

  • @tudor_nechiti
    @tudor_nechiti ปีที่แล้ว +1

    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.

    • @m3hdim3hdi
      @m3hdim3hdi 7 หลายเดือนก่อน

      HTTPie

  • @hamidrezarezaei1623
    @hamidrezarezaei1623 ปีที่แล้ว

    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.

  • @VLADICA94KG
    @VLADICA94KG ปีที่แล้ว +1

    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. 😀

  • @elhadjibrahimabalde1234
    @elhadjibrahimabalde1234 7 หลายเดือนก่อน

    great tutorial thanks

  • @Juanj0se22
    @Juanj0se22 ปีที่แล้ว

    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!

  • @anandsingh-pw6mm
    @anandsingh-pw6mm ปีที่แล้ว

    Loved the content and appreciate the effort, I often struggle with writing better logs which actually meaningful when time comes, what your say on it. TIA Anand

  • @viratsuresh5946
    @viratsuresh5946 ปีที่แล้ว

    Dan, can you cover integration test cases using H2 database

  • @menabebawy390
    @menabebawy390 ปีที่แล้ว

    Awesome dude

  • @alexswak
    @alexswak 8 หลายเดือนก่อน +1

    I assume you are not going to write sql schemas all the time? It's a great video, but my gripe with such tutorials is that they most of the time don't show the complexity of real world scenarios. Two big aspects lacking here in my opinion:
    1- handling migrations to the testcontainer in a more realistic way than writing schemas manually.
    2- handling authentication.
    It's a great video nonetheless and much appreciated, but I hope you can talk more about that and show use cases that are more "real-world".

  • @scrumtuous
    @scrumtuous ปีที่แล้ว +3

    Learned so much!

    • @DanVega
      @DanVega  ปีที่แล้ว +1

      Thank you for watching 🤩

  • @manoelcamposdev
    @manoelcamposdev ปีที่แล้ว

    The spring-boot-starter-data-jdbc was missing in my project.

  • @hamidoubalde2517
    @hamidoubalde2517 8 หลายเดือนก่อน

    @Dan Vega is it possible to test security context when making these tests? Thanks

  • @trimalakismeno
    @trimalakismeno หลายเดือนก่อน

    @Dan Vega the problem with this setup is that you get errors in the tests since there is no @Transactional to roll back every change, how do you solve that?

  • @stephaneislistening6103
    @stephaneislistening6103 5 หลายเดือนก่อน

    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.

  • @eddylequartier
    @eddylequartier 9 หลายเดือนก่อน

    Hello Dan. I do not understand why i got this message when i launch test into Intellij IDEA : " java: invalid source release 19 with --enable-preview
    (preview language features are only supported for release 21) " All is fine, in terminal with mvn command "mvn clean test" but not in the IDE. why ?

  • @ПетришакВасиль
    @ПетришакВасиль 9 หลายเดือนก่อน

    What is the best way to configure test container in multi-module gradle project?

  • @TheMyth2.9
    @TheMyth2.9 9 หลายเดือนก่อน

    Hey this is good, i just want to ask, what if i want to test the database with the @DataJpaTest without the whole App context, could I use this ? Also if I want a fixed port, Cant I just pull the url & passwords from the .properties files ?

  • @codeful_dev
    @codeful_dev 11 หลายเดือนก่อน

    I don't think the transactional is working as we think in the video:
    According to the Spring Boot 3.2 Docs:
    If your test is @Transactional, it rolls back the transaction at the end of each test method by default. However, as using this arrangement with either RANDOM_PORT or DEFINED_PORT implicitly provides a real servlet environment, the HTTP client and server run in separate threads and, thus, in separate transactions. Any transaction initiated on the server does not roll back in this case.
    Why are the Spring Boot docs better than the Spring Framework? I have been muddling through this issue.

  • @ahmetsahin2450
    @ahmetsahin2450 7 หลายเดือนก่อน

    How to create tables for database while using JDBC?

  • @maneshipocrates2264
    @maneshipocrates2264 ปีที่แล้ว +2

    Great stuff.

    • @DanVega
      @DanVega  ปีที่แล้ว +1

      Thanks!

  • @vivekguptacs
    @vivekguptacs 3 หลายเดือนก่อน

    Does testcontainer support sqlserver as well instead of postgress

  • @hanumanthram6754
    @hanumanthram6754 ปีที่แล้ว +1

    I have a doubt. Without configuring the datasouce (url, username, password) how it is working and storing the data in db?

    • @stefumies
      @stefumies 5 หลายเดือนก่อน

      Its not you are correct, in fact Im suprised its working here as no jdbc connection has been setup in the repo application.properties file

  • @mehnaazmohiuddin
    @mehnaazmohiuddin ปีที่แล้ว

    in public void setup we are using the system undertest . is this ok ?

  • @m3hdim3hdi
    @m3hdim3hdi 7 หลายเดือนก่อน

    didnt work for me the image does not get pulled
    edit: i was using @Test from junit 4 instead of 5

  • @JamilJB
    @JamilJB 9 หลายเดือนก่อน +3

    It's not easy at all. We have used testcontainers for blackbox testing. It depends on the microservice, but it took 1-3 min to build up the entire test environment. Their experimental feature allows us to reuse docker networks. So I could reduce the time to build up containers to 20-30 seconds. The second problem is to automate these tests, automic jar is not a solution for this problem. It's just a way of solving a problmen when you have no solution. In conclusion, it's not easy to write integrationtests with testcontainer. It will have consequences for the projects. There are reasons to use this framework for sure but there are also weak points and if you are not solve these weak points, then this framework will turn against you

    • @DanielRevotiuk
      @DanielRevotiuk 2 หลายเดือนก่อน

      Which way of integrationtesting do you prefer as an engineer? I have no working expirience so I hope you'll share about your preferences. Thank you

  • @sohaibelbokhari8319
    @sohaibelbokhari8319 5 หลายเดือนก่อน

    i think that @Transactional rollback could not be done when we performe http call in integration tests

    • @trimalakismeno
      @trimalakismeno หลายเดือนก่อน

      I am actually facing this issue

    • @sohaibelbokhari8319
      @sohaibelbokhari8319 หลายเดือนก่อน +1

      @@trimalakismeno u have to use a H2 DB for test.

    • @trimalakismeno
      @trimalakismeno หลายเดือนก่อน

      @@sohaibelbokhari8319 i've seen that suggestion elsewhere as well, thanks!

  • @jeffreysmith9837
    @jeffreysmith9837 2 หลายเดือนก่อน

    you try to cut down on time so much it just turns out sloppy

  • @sarkar_957
    @sarkar_957 ปีที่แล้ว +6

    You are always best sir!!

    • @DanVega
      @DanVega  ปีที่แล้ว +4

      Thank you so much 😀

  • @nathanlively
    @nathanlively ปีที่แล้ว

    Hey Dan, I followed along with you, but I'm getting this error: Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: org/springframework/data/jdbc/repository/config/AbstractJdbcConfiguration [in thread "main"]
    Maybe it won't work since I'm using JPA instead of JDBC?

    • @TheoHavard
      @TheoHavard 3 หลายเดือนก่อน +2

      In case someone else got the issue:
      You need to change the annotation of the *RespositoryTest class from @DataJdbcTest to @DataJpaTest