Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore how to set up base test case with local SQL DB access #18

Closed
zhaojj2209 opened this issue Aug 13, 2022 · 4 comments
Closed

Explore how to set up base test case with local SQL DB access #18

zhaojj2209 opened this issue Aug 13, 2022 · 4 comments
Assignees

Comments

@zhaojj2209
Copy link
Owner

zhaojj2209 commented Aug 13, 2022

Explore how to write component tests (e.g. for course) against SQL DB. Run tests for CoursesDb, CoursesLogic, and a few course-only APIs.

Updated:
The current most viable solution is to use throwaway instances of databases running in Docker containers.

There are two options we can consider:

  • Option A: OpenTable Embedded PostgreSQL Component
    • This library is maintained by OpenTable, Inc. It uses TestContainers under the hood, but adds value with builders, the api compatibility, the wrapping around Flyway to allow users to adopt a smooth transition to a Docker-based test approach.
  • Option B: TestContainers
    • We can also directly use TestContainers, a well-known Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases
    • We will need to integrate Flyway with TestContainers ourselves
@jianhandev jianhandev self-assigned this Aug 14, 2022
@jianhandev
Copy link
Collaborator

Currently focusing on issue #16, if anyone has time to explore this feel free to reassign this to yourself.

@jianhandev jianhandev removed their assignment Aug 25, 2022
@hhdqirui hhdqirui self-assigned this Sep 25, 2022
@hhdqirui
Copy link
Collaborator

An alternative is to use an embedded PostgreSQL database for unit testing.
Pros: It seems that it is relatively easier to set up the entire testing framework. It can be installed and managed by Gradle. It can used to write JUnit tests.
Cons: This library seems to be less well-known. Moreover, since it is not a real PostrgreSQL instance, the behaviour might be different from a real PostgreSQL instance.
https://github.com/opentable/otj-pg-embedded
https://github.com/zonkyio/embedded-postgres

@jianhandev
Copy link
Collaborator

An alternative is to use an embedded PostgreSQL database for unit testing.

Thanks for suggesting the alternatives. Let's consolidate out findings in this google doc, I did some quick research there could be many approaches to this.

https://docs.google.com/document/d/1OATm_5TuzpFQPJ6uor2J4MbHRL5-Zg9hCV3rnbcCm3I/edit

@jianhandev
Copy link
Collaborator

There are two options we can consider:

  • Option A: OpenTable Embedded PostgreSQL Component

    • This library is maintained by OpenTable, Inc. It uses TestContainers under the hood, but adds value with builders, the api compatibility, the wrapping around Flyway to allow users to adopt a smooth transition to a Docker-based test approach.
  • Option B: TestContainers

    • We can also directly use TestContainers, a well-known Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases
    • We will need to integrate Flyway with TestContainers ourselves

@hhdqirui would you like to work on this? I think either option might work for us, OpenTable Embedded PostgreSQL Component would be easier to get started with. We also need to explore how to integrate it successfully in our CI/CD pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants