Skip to content

3.4 @MockBean to @MockitoBean Not Behaving The Same - Cross Post of "Support @MockitoBean on @Configuration classes #33934" #43282

Closed
@adase11

Description

@adase11

This is a cross post of spring-projects/spring-framework#33934 - I think it's useful to mention here.

I believe most people will run into this issue for the first time when upgrading to Spring Boot 3.4.

At a high level @MockitoBean is no longer behaving the same as @MockBean was when used in tests.

The examples in spring-projects/spring-framework#33934 as well as my experience are specifically referencing @WebMvcTest (which is from Spring Boot and why I think this should be brought up here).

Shout out to @tobias-lippert for the initial post with a solid example.


Ideally @MockitoBean would be a drop-in replacement for @MockBean and those test-specific configuration classes would continue to work. Alternatively I think it would be useful to document the need to move those @MockitoBean declarations to the test class itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions