Testing

Spring Boot + PostgreSQL – Integration Testing with Testcontainers

Integration testing is critical for ensuring that your application interacts correctly with external systems. In this project, we demonstrate how to perform integration testing in a Spring Boot application using PostgreSQL as the database and Testcontainers to run a real PostgreSQL instance during tests. This approach helps create a production-like, isolated, and repeatable testing environment. […]

Spring Boot + PostgreSQL – Integration Testing with Testcontainers Read More »

Spring Boot + DataMongoTest + Testcontainers: Testing MongoDB Repositories with a MongoDB Container

Introduction The @DataMongoTest annotation in Spring Boot is designed for isolated testing of MongoDB repositories. By default, it configures an embedded MongoDB (Flapdoodle) for testing. However, in real-world scenarios, we might need to test against a real MongoDB instance without installing it locally. This is where Testcontainers comes in. What is Testcontainers? Testcontainers is a

Spring Boot + DataMongoTest + Testcontainers: Testing MongoDB Repositories with a MongoDB Container Read More »

Spring Boot + DataMongoTest: Testing MongoDB Repositories with Embedded MongoDB (Flapdoodle)

Introduction The @DataMongoTest annotation in Spring Boot is designed for isolated testing of MongoDB repositories. It automatically configures an embedded MongoDB instance using Flapdoodle, which eliminates the need for a real database. By default, @DataMongoTest: Automatically configures an in-memory MongoDB instance (Flapdoodle). Loads only MongoDB-related components (documents, repositories, etc.). Rolls back changes after each test,

Spring Boot + DataMongoTest: Testing MongoDB Repositories with Embedded MongoDB (Flapdoodle) Read More »

Spring Boot + DataMongoTest: Testing MongoDB Repositories with a Real Database

Introduction The @DataMongoTest annotation in Spring Boot is specifically designed for isolated testing of MongoDB repositories. It loads only MongoDB-related components, ensuring fast and efficient tests. By default, @DataMongoTest: Automatically configures an embedded MongoDB instance (Flapdoodle). Rolls back changes after each test, keeping the database clean. Excludes unnecessary beans (@Service, @Controller), making tests lightweight. However,

Spring Boot + DataMongoTest: Testing MongoDB Repositories with a Real Database Read More »

Spring Boot + DataJpaTest: Testing JPA Repositories with H2 Database

Introduction The @DataJpaTest annotation in Spring Boot is specifically designed for isolated testing of JPA repositories. Instead of bootstrapping the entire Spring Boot application, it loads only JPA-related components such as: ✅ @Entity classes✅ Spring Data JPA repositories✅ Database configuration What Happens When Using @DataJpaTest? By default, @DataJpaTest: Automatically configures an in-memory database (H2, HSQLDB,

Spring Boot + DataJpaTest: Testing JPA Repositories with H2 Database Read More »

Spring Boot + DataJpaTest: Testing JPA Repositories with a Real Database

Introduction The @DataJpaTest annotation in Spring Boot is specifically designed for testing JPA repositories in an isolated manner. Instead of bootstrapping the entire application context, it initializes only the components relevant to JPA, such as entities, repositories, and the database configuration. By default, @DataJpaTest: Scans for @Entity classes and configures Spring Data JPA repositories. Automatically

Spring Boot + DataJpaTest: Testing JPA Repositories with a Real Database Read More »