What is the significance of @SpringBootTest(classes = YourClass.class)?
It makes a Spring Boot test build its context from the classes you list instead of the discovered application class, giving focused and faster integration tests.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
It makes a Spring Boot test build its context from the classes you list instead of the discovered application class, giving focused and faster integration tests.
Use @DataJpaTest to run repository tests against a real database in a rolled-back transaction. Learn flushing, custom query tests and Testcontainers setup.
@DataJpaTest loads only the JPA slice of a Spring Boot app so you can test repositories and queries fast, with an embedded or Testcontainers database.
Use @WebMvcTest, MockMvc and a mocked service to test controller responses without a server, plus how to fake external HTTP calls.
@WebMvcTest isolates the web layer in Spring tests. Compare it with other test slices, see a MockMvc example, and learn how to handle security and mocks.
Add JaCoCo to Maven or Gradle, run the tests and read the HTML report. Learn exclusions, coverage thresholds and how to publish in CI.
Learn how to structure tests for Spring Boot: fast unit tests, slice tests, Testcontainers integration tests and habits that keep the suite reliable.
Plan and run load, stress and soak tests on a Spring application with Gatling, JMeter or k6, and find the bottlenecks they reveal.
The @SpringBootTest annotation starts the full Spring Boot application context so you can write integration tests, with options for web mode, properties and mocks.
Wait on the returned CompletableFuture with a timeout, poll with Awaitility for void methods, and verify exceptions and threads when testing @Async code in Spring.
@MockBean puts a Mockito mock into the Spring test context so beans receive a controllable fake. Learn how to use it and migrate to @MockitoBean.
Create mocks with @Mock, inject them with @InjectMocks, stub calls and verify interactions. A complete JUnit 5 example with Mockito 5 and best practices.
TestRestTemplate calls your running Spring Boot endpoints over HTTP in tests. See setup, POST and auth examples and how it compares with MockMvc.
Use @SpringBootTest, test slices and Testcontainers to verify that your Spring Boot beans, database and web layer work together as in production.
MockMvc tests Spring MVC controllers in memory, checking mappings, validation, JSON and security without a server. See setups and examples.
Use @WebMvcTest, MockMvc and @MockitoBean to test Spring MVC controllers: requests, JSON assertions, validation, exception handling and secured endpoints.
Flyway is SQL-first and simple; Liquibase is declarative with richer rollback and portability. See how they compare and which one fits your project.
Flyway and Liquibase record every applied schema change in a history table. Learn how to set up either one in Spring Boot and keep migrations safe.
Liquibase applies versioned database changes automatically when a Spring Boot application starts. See how to configure changelogs, contexts and rollbacks.
Set up Flyway database migrations in Spring Boot with dependencies, naming rules, properties, baselining and safe production practices.