A Java project demonstrating JPA (Jakarta Persistence API) testing with Testcontainers, using PostgreSQL as the database.
This project showcases how to:
- Set up JPA with PostgreSQL using Testcontainers for testing
- Implement proper test isolation
- Handle database schema generation
- Manage test data effectively
- Use modern Java testing practices
- Java 21 or later
- Maven 3.8 or later
- Docker Desktop (for running Testcontainers)
src/
├── main/
│ ├── java/
│ │ └── com/
│ │ └── jpawithtestcontainers/
│ │ └── model/
│ │ └── Customer.java
│ └── resources/
│ └── META-INF/
│ └── persistence.xml
└── test/
├── java/
│ └── com/
│ └── jpawithtestcontainers/
│ └── TestContainerJPA.java
└── resources/
└── META-INF/
└── persistence.xml
-
Clone the repository:
git clone https://github.com/aripddev/JPAWithTestContainers.git cd JPAWithTestContainers -
Make sure Docker Desktop is running
-
Build the project:
mvn clean install
Run all tests:
mvn test- Each test runs in isolation with a clean database state
- Proper setup and teardown of test data
- Consistent test environment using Testcontainers
- PostgreSQL container managed by Testcontainers
- Automatic schema generation
- Proper transaction handling
- Comprehensive assertions
- Clear test naming and organization
- Proper resource cleanup
- Jakarta Persistence API 3.0
- EclipseLink 5.0.0-B01
- PostgreSQL JDBC Driver 42.7.5
- Testcontainers 1.20.6
- JUnit Jupiter 5.13.0-M1
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.