SpringExtension for JUnit 5: Why Do We Need It?
SpringExtension integrates the Spring TestContext Framework into JUnit 5 Jupiter extension model, sets up the ApplicationContext, and manages dependencies.
SpringExtension integrates the Spring TestContext Framework into JUnit 5 Jupiter extension model, sets up the ApplicationContext, and manages dependencies.
Spring @Sql executes DDL and DML SQL scripts and statements during the integration testing. @SqlGroup groups multiple @Sql statements.
Use @RestClientTest and MockRestServiceServer to verify an outgoing Spring Boot 4 RestClient request, JSON mapping, and 404 handling with runnable tests.
Test Spring Data JPA repositories with @DataJpaTest on Spring Boot 4.1.2. Run H2 query tests, verify rollback behavior, and see how to keep a configured datasource.
Use Spring Boot 4 @MockitoBean in MVC slice and full-context controller tests. Compare it with a plain Mockito mock and see when a missing bean is created or an existing one replaced.
Test a Spring WebFlux controller with @WebFluxTest, WebTestClient and @MockitoBean on Spring Boot 4.1.2. Verify JSON, 404 responses and the difference from a live-server test.
The @SpringBootTest annotation in Spring Boot allows us to create integration tests by loading the entire application context. It acts as a bridge between the application configuration and the test framework so that tests can verify the behavior of your application in an environment similar to production.
Use Spring Boot @TestConfiguration to add fixed test beans without losing production wiring. Compare nested and imported configurations in a runnable Boot 4.1.2 example.
Learn to include JUnit 5 in a Spring boot application and write unit tests. Check out a demo of JUnit 5 tests for Spring Boot REST controller.
Test Spring Boot REST controllers with MockMvc and @WebMvcTest. Replace the service with a @MockitoBean mock and send GET, POST, PUT and DELETE requests with JSON. Then check status codes, validation errors and @RestControllerAdvice responses. Also covers MockMvcTester (AssertJ) and real andDo(print()) output on Spring Boot 4.1.1.
Test Java repositories with an isolated database. Check query boundaries and returned records, choose the right database and keep tests independent.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.