Replacing the Default In-Memory Database of @DataJpaTest Using Testcontainers

Поделиться
HTML-код
  • Опубликовано: 9 фев 2025

Комментарии • 11

  • @Caranthirn
    @Caranthirn 2 года назад +1

    Thank you

  • @mauroa2826
    @mauroa2826 2 года назад

    Have you a tutorial with MySQL connection?

    • @rieckpil
      @rieckpil  2 года назад

      Unfortunately not, but the presented technique also applies to any other RDBMS. For MySQL, you can use the MySQL Testcontainers module: www.testcontainers.org/modules/databases/mysql/

  • @AmNotLegend
    @AmNotLegend 3 года назад

    about the image: is "postgres:12" an existing image?

    • @rieckpil
      @rieckpil  3 года назад +1

      Yes, it's the official PostgreSQL image hub.docker.com/_/postgres

    • @AmNotLegend
      @AmNotLegend 3 года назад

      @@rieckpil thanks

  • @Das.Kleine.Krokodil
    @Das.Kleine.Krokodil 2 года назад

    1:08 Why don't I have this error and the test passes correctly? I have these settings:
    spring.datasource.driver-class-name=org.postgresql.Driver
    spring.datasource.url=jdbc:postgresql://localhost:5432/database1
    spring.datasource.username=postgres
    spring.datasource.password=postgres

  • @AmNotLegend
    @AmNotLegend 3 года назад

    it seems that BOM doesn't really work; @Testcontainers is not recognized. I used the following both, then it becomes fine

    org.testcontainers
    postgresql
    1.15.3
    test


    org.testcontainers
    junit-jupiter
    1.15.3
    test

    • @rieckpil
      @rieckpil  3 года назад +1

      Hm not sure what's going wrong on your side there. I'm using the Testcontainers BOM in multiple projects and it works fine for me, e.g. see here github.com/rieckpil/testing-spring-boot-applications-masterclass/blob/master/pom.xml
      You can also work without the BOM but then have to bump all version definitions if there's a new Testcontainers release.

    • @AmNotLegend
      @AmNotLegend 3 года назад +1

      @@rieckpil Yea, you are right. applying BOM is better; my IDE cannot recognize the BOM yesterday. Right now it is good.

  • @Das.Kleine.Krokodil
    @Das.Kleine.Krokodil 2 года назад

    Thank you