Skip to content

@MockBean combined with @Repeat results in "the field cannot have an existing value" error #27693

@alexey-anufriev

Description

@alexey-anufriev

I need to run Spring Test concurrently. For this reason, a separate method rule has been created.
The logic of this rule (code included in reproducer) is to execute the test method multiple times in a dedicated executor.

Unfortunately injection flow does not work as excepted and throws the following exception:

org.springframework.beans.factory.BeanCreationException: Could not inject field: <xxx>; 
    nested exception is java.lang.IllegalStateException: The field <xxx> cannot have an existing value
	at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.inject(MockitoPostProcessor.java:364)

Reproducer and instruction are here: https://github.com/alexey-anufriev/spring-test-concurrent-execution-problem

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions