Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding @MockitoSettings to class changes order of extensions in @ExtendWith #3255

Open
magicwerk opened this issue Jan 29, 2024 · 0 comments

Comments

@magicwerk
Copy link

JUnit initializes extensions in the order they are declared in @ExtendWith.
So in the test below, initialization should be done in order SetupExtension, MockitoExtension.
This works fine, unless the annotation
@MockitoSettings(strictness = Strictness.LENIENT)
is added which changes this behavior and MockitoExtension is initialized first.
If the annotation is commented out, behavior is as expected.

This is probably related to #3254

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'

@MockitoSettings(strictness = Strictness.LENIENT)
@ExtendWith({ SetupExtension.class, MockitoExtension.class })
public class EvalMockitoJUnitExtension2 {

	static class SetupExtension implements BeforeEachCallback {
		@Override
		public void beforeEach(ExtensionContext context) {
			System.out.println("SetupExtension before");
		}
	}

	static class MyMock {
		MyMock() {
			System.out.println("MyMock");
		}
	}

	@Spy
	MyMock myMock;

	@Test
	public void test() {
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant