You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My test uses Mockito mocks so I want to use MockitoExtension supporting this.
I also need another extension SetupExtension which I must be able to configure in the test method, so this extension is added using @RegisterExtension.
I need to control the order of initialization, so I use @order and therefore also declare MockitoExtension using @RegisterExtension.
I need to use Strictness.LENIENT on the MockitoExtension.
However if I add @MockitoSettings to the mockitoExtension field, test fails.
I did not find any other way to set strictness, as constructor MockitoExtension(Strictness strictness) is private.
See the following test case reproducing the issue.
If test is executed, it fails with
org.junit.platform.commons.PreconditionViolationException: Failed to register extension via field [org.mockito.junit.jupiter.MockitoExtension eval.mockito.EvalMockitoJUnitExtension.mockitoExtension]. The field registers an extension of type [org.mockito.junit.jupiter.MockitoExtension] via @RegisterExtension and @ExtendWith, but only one registration of a given extension type is permitted.
If I comment the line
// @MockitoSettings(strictness = Strictness.LENIENT)
the test runs fine (but I need to be able to set the strictness)
My test uses Mockito mocks so I want to use MockitoExtension supporting this.
I also need another extension SetupExtension which I must be able to configure in the test method, so this extension is added using @RegisterExtension.
I need to control the order of initialization, so I use @order and therefore also declare MockitoExtension using @RegisterExtension.
I need to use Strictness.LENIENT on the MockitoExtension.
However if I add @MockitoSettings to the mockitoExtension field, test fails.
I did not find any other way to set strictness, as constructor MockitoExtension(Strictness strictness) is private.
See the following test case reproducing the issue.
If test is executed, it fails with
org.junit.platform.commons.PreconditionViolationException: Failed to register extension via field [org.mockito.junit.jupiter.MockitoExtension eval.mockito.EvalMockitoJUnitExtension.mockitoExtension]. The field registers an extension of type [org.mockito.junit.jupiter.MockitoExtension] via @RegisterExtension and @ExtendWith, but only one registration of a given extension type is permitted.
If I comment the line
// @MockitoSettings(strictness = Strictness.LENIENT)
the test runs fine (but I need to be able to set the strictness)
Versions used:
'org.mockito:mockito-core:5.10.0'
'org.mockito:mockito-junit-jupiter:5.10.0'
'org.junit.jupiter:junit-jupiter:5.10.1'
'org.junit.jupiter:junit-jupiter-engine:5.10.1'
'org.junit.platform:junit-platform-launcher:1.10.0'
The text was updated successfully, but these errors were encountered: