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
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6185,6 +6185,11 @@ We recommend using a `@Bean` method to create and configure the mock in this sit
6185
6185
Additionally, you can use `@SpyBean` to wrap any existing bean with a Mockito `spy`.
6186
6186
See the {spring-boot-test-module-api}/mock/mockito/SpyBean.html[Javadoc] for full details.
6187
6187
6188
+
NOTE: CGLib proxies, such as those created for scoped beans, declare the proxied methods as `final`.
6189
+
This stops Mockito from functioning correctly as it cannot mock or spy on `final` methods in its default configuration.
6190
+
If you want to mock or spy on such a bean, configure Mockito to use its inline mock maker by adding `org.mockito:mockito-inline` to your application's test dependencies.
6191
+
This allows Mockito to mock and spy on `final` methods.
6192
+
6188
6193
NOTE: While Spring's test framework caches application contexts between tests and reuses a context for tests sharing the same configuration, the use of `@MockBean` or `@SpyBean` influences the cache key, which will most likely increase the number of contexts.
6189
6194
6190
6195
TIP: If you are using `@SpyBean` to spy on a bean with `@Cacheable` methods that refer to parameters by name, your application must be compiled with `-parameters`.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForExistingScopedBeanIntegrationTests.java
0 commit comments