You bump the Spring Boot version to 4, run the build, and the main code compiles fine. Then the tests fail with a wall of errors like these:

cannot find symbol
symbol: class MockBean
package org.springframework.boot.test.autoconfigure.web.servlet does not exist
The test code itself is fine. Spring Boot 4 removed @MockBean and @SpyBean, split the test starter into one starter per technology, and moved the slice annotations like @WebMvcTest and @DataJpaTest to new packages.

Once you know the new names, the fixes are mostly search and replace. Below is each one, shown on a small Books app with three tests that pass on Spring Boot 4.1.2.

The app under test
A Book entity, a repository, a service and a controller with one endpoint:

`@RestController
@RequestMapping("/books")
public class BookController {

private final BookService service; public BookController(BookService service) { this.service = service; } @GetMapping("/{id}") public Book get(@PathVariable long id) { return service.get(id); } @ExceptionHandler(BookNotFoundException.class) ProblemDetail notFound(BookNotFoundException e) { return ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, e.getMessage()); } 

}
@Service
public class BookService {

private final BookRepository books; public BookService(BookRepository books) { this.books = books; } public Book get(long id) { return books.findById(id).orElseThrow(() -> new BookNotFoundException(id)); } 

}
public interface BookRepository extends JpaRepository {
List findByAuthor(String author);
}`

Book is a plain JPA entity with id, title and author, and the app uses an in-memory H2 database.

Fix 1: Test dependencies
In Boot 3, spring-boot-starter-test gave you everything. In Boot 4, each technology has its own test starter, and the slice annotations only exist if you add the matching one:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
<scope>test</scope>
</dependency>

Both include JUnit, AssertJ and Mockito, so you don't need spring-boot-starter-test next to them. There are matching ones for other modules too, for example spring-boot-starter-security-test and spring-boot-starter-data-redis-test.

As a rule of thumb, if the app has spring-boot-starter-X, the tests probably need spring-boot-starter-X-test.

Fix 2: @MockBean becomes @MockitoBean
Here's a controller test on Boot 4:

`import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.assertj.MockMvcTester;

@WebMvcTest(BookController.class)
class BookControllerTest {

@Autowired MockMvcTester mvc; @MockitoBean BookService service; @Test void returnsBook() { when(service.get(1L)).thenReturn(new Book("Dune", "Frank Herbert")); assertThat(mvc.get().uri("/books/1")) .hasStatusOk() .bodyJson().extractingPath("$.title").isEqualTo("Dune"); } @Test void missingBookIs404() { when(service.get(99L)).thenThrow(new BookNotFoundException(99L)); assertThat(mvc.get().uri("/books/99")) .hasStatus(404) .bodyJson().extractingPath("$.detail").isEqualTo("Book 99 not found"); } 

}`

Three changes from a Boot 3 test:

@MockBean is now @MockitoBean. It comes from Spring Framework itself (org.springframework.test.context.bean.override.mockito), not from Boot. You use it the same way: put it on a field and stub it with when(...).
@WebMvcTest moved from org.springframework.boot.test.autoconfigure.web.servlet to org.springframework.boot.webmvc.test.autoconfigure.
The test uses MockMvcTester instead of MockMvc. This one is optional, and the old MockMvc with perform(...) and andExpect(...) still works. MockMvcTester gives you AssertJ-style assertions, and it doesn't throw checked exceptions, so throws Exception disappears from every test method. @WebMvcTest sets it up for you.
Fix 3: @SpyBean becomes @MockitoSpyBean
A spy wraps the real bean, so real code runs and you can still verify calls. Here it wraps the real repository in a full @SpringBootTest:

`import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;

@SpringBootTest
class BookServiceTest {

@Autowired BookService service; @MockitoSpyBean BookRepository books; @Test void readsFromTheRealRepository() { Book saved = books.save(new Book("Dune", "Frank Herbert")); assertThat(service.get(saved.getId()).getTitle()).isEqualTo("Dune"); verify(books).findById(saved.getId()); } 

}`

The save goes to the real H2 database, the service reads it back, and verify confirms the service called findById. @SpringBootTest itself didn't move.

Fix 4: @DataJpaTest and TestEntityManager moved

`import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
import org.springframework.boot.jpa.test.autoconfigure.TestEntityManager;

@DataJpaTest
class BookRepositoryTest {

@Autowired BookRepository books; @Autowired TestEntityManager em; @Test void findsByAuthor() { em.persist(new Book("Dune", "Frank Herbert")); em.persist(new Book("Neuromancer", "William Gibson")); assertThat(books.findByAuthor("Frank Herbert")) .extracting(Book::getTitle) .containsExactly("Dune"); } 

}`

The two imports live in different packages, which makes them easy to mix up:

@DataJpaTest is in org.springframework.boot.data.jpa.test.autoconfigure
TestEntityManager is in org.springframework.boot.jpa.test.autoconfigure (no data)
Both used to sit together in org.springframework.boot.test.autoconfigure.orm.jpa.

The import cheat list
Search and replace these across your test folder:

org.springframework.boot.test.mock.mockito.MockBean → org.springframework.test.context.bean.override.mockito.MockitoBean
org.springframework.boot.test.mock.mockito.SpyBean → org.springframework.test.context.bean.override.mockito.MockitoSpyBean
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest → org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc → org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest → org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest
org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager → org.springframework.boot.jpa.test.autoconfigure.TestEntityManager
Then rename the annotations themselves: @MockBean to @MockitoBean and @SpyBean to @MockitoSpyBean.

Where the rename isn't enough
Mocks declared in a configuration class
Some projects put @MockBean on fields of a shared @TestConfiguration. @MockitoBean only works on fields of the test class (or its superclasses and interfaces), so move those mocks into a base test class that the tests extend.

@MockBean on the test class itself
In Boot 3 you could write @MockBean(BookService.class) on the class. The replacement is @MockitoBean(types = BookService.class), also on the class.

The slice annotation still can't be found
If the import is fixed and the compiler still complains, you're missing the test starter for that module (see Fix 1), so the class isn't on the classpath.

Security tests suddenly return 401 or 403
@WebMvcTest loads your security config when it exists. Add spring-boot-starter-security-test and use @WithMockUser, or test the controller without filters using @AutoConfigureMockMvc(addFilters = false).

Run it
Put the classes above in a Boot 4.1 project with the two test starters and an H2 dependency, then run:

mvn test
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
Wrapping up
Most of a Boot 4 test migration is renaming two annotations, swapping six imports and adding the right test starters. The part that takes real work is mocks shared through configuration classes, so check for those first when you estimate the upgrade.

Tests are only one of the places Boot 4 moved things around. Starters got new names, Jackson 3 replaced Jackson 2, and security setup changed too. I collected all of it in my Spring Boot 4 Cheat Sheet: 48 pages of code from one real app that compiles on Spring Boot 4.1, plus 55 interview answers, 22 common errors with their fixes, and the full source project with its tests.

It now comes with a free bonus, the Spring Boot Starter Kit (worth $29). It's one task-tracker app built three times, going from a plain REST API to JWT login, rate limiting, an outbox, metrics, tracing, Docker and Kubernetes. It has modules for Kafka, Redis, MongoDB, MySQL and Cassandra, plus a script that turns it into your own project. It runs on Spring Boot 4.1 and Java 25 with 220 passing tests, and you get it as a second download with the cheat sheet.

Both together are $9.99, with a 30-day refund if they don't help: Spring Boot 4 Cheat Sheet + Interview Guide.

Hit a test error after upgrading that isn't covered here? Paste it in the comments and I'll help you fix it.