Springboottest Articles
4 articles about Springboottest. Explore Spring Boot implementation, design, and operations across related topics.
-
How to Load Test Data in Spring Boot Tests Using the @Sql Annotation
Learn how to use the @Sql annotation with @DataJpaTest and @SpringBootTest to declaratively load fixture data for each test. Covers how to use executionPhase and errorMode, the difference from data.sql, and more, with practical examples.
-
Spring Boot @SpringBootTest webEnvironment Guide - Choosing Between MOCK, RANDOM_PORT, DEFINED_PORT, and NONE
A comparison table and working code clarify what each of the four @SpringBootTest webEnvironment modes (MOCK/RANDOM_PORT/DEFINED_PORT/NONE) does and does not start up. Covers replacing external dependencies with @MockitoBean, splitting scenarios with @Nested, and the cases where launching the full ApplicationContext is truly necessary.
-
How to Write Real HTTP E2E Tests in Spring Boot with @SpringBootTest(RANDOM_PORT) and TestRestTemplate
Learn how to actually launch your application with @SpringBootTest(webEnvironment = RANDOM_PORT) and write integration tests that verify status codes, headers, and bodies using TestRestTemplate. Covers the differences from MockMvc, sending requests to authenticated endpoints, and validating error responses, all with working code examples.
-
Let's Write Tests in Spring Boot - An Introduction to Unit Testing with JUnit and Mockito
A step-by-step guide to writing unit tests for Spring Boot with JUnit 5 and Mockito, covering the Service layer (@Mock/@InjectMocks) and the Controller layer (@WebMvcTest/@MockBean/MockMvc) separately. Learn through concrete code examples including the Given-When-Then pattern, normal and abnormal cases, and assertThrows.