Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Testing data repositories with Testcontainers

Pragya Keshap answered on February 15, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • test @value spring boot
  • Use @Test Annotation on Test Methods
  • Testing in Spring Boot
  • Using Testcontainers
  • running same tests against different data
  • How to configure separate datasource for test
  • How to configure separate datasource for test
  • How to configure separate datasource for test
  • Test Configuration With @TestConfiguration
  • Testing data persistence with @DataR2dbcTest and Testcontainers
  • Testing data repositories with mocks
  • Adding Testcontainers to the application
  • Testing data repositories with embedded databases
  • testContainer with Junit

  • Testing data repositories with Testcontainers

    0

    This framework for test cases can be described as follows:

    @Testcontainers: The annotation from the Testcontainers junit-jupiter module that hooks into the life cycle of a JUnit 5 test case.

    @DataJpaTest: Spring Boot Test’s annotation we used in the previous section, indicating that all entity classes and Spring Data JPA repositories should be scanned.

    @AutoConfigureTestDatabase: This Spring Boot Test annotation tells Spring Boot that instead of swapping out the DataSource bean like it normally does, to instead NOT replace it like it normally does when there’s an embedded database on the classpath (more on why this is needed shortly).

    @Autowired VideoRepository: Injects the application’s Spring Data repository. We want the real thing and not some mock because this is what we’re testing!

    @Container: Testcontainer’s annotation to flag this as the container to control through the JUnit life cycle.

    PostgreSQLContainer: Creates a Postgres instance through Docker. The constructor string specifies the Docker Hub coordinates of the exact image we want. Note that this makes it easy to have multiple test classes, each focused on different versions of Postgres!

    https://medium.com/javarevisited/database-integration-testing-with-testcontainers-8b4be2404a55

    Popularity 1/10 Helpfulness 1/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 15 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.