Skip to content

Support @MockBean for a MyBatis mapper interface #475

Closed
@dldiehl77

Description

@dldiehl77

I am using MyBatis Spring Boot Starter version 2.1.3. Ever since moving to Spring Boot 2.2.7 (I've also tried 2.2.8 and 2.3.1 with the same results), I've had a problem using the MockBean annotation to mock a MyBatis interface (e.g. DAO or Mapper).

I have a MyBatis interface annotated with both Mapper and Repository. When I try to use the Spring Boot MockBean annotation, the object that is injected into my Service classes and the object that is injected into my unit test class are not the same, making it so that I cannot use Mockito.verify (as an example of one issue this causes).

A complete description is on stackoverflow here: https://stackoverflow.com/questions/62409666/mockbean-and-mybatis-mapper-not-working-together-as-they-did-before-spring-boot

Including a demo of the issue here: github.com/dldiehl77/mybatis-issues/tree/master/so-62409666

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions