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
@@ -5801,6 +5801,11 @@ We recommend using a `@Bean` method to create and configure the mock in this sit
5801
5801
Additionally, you can use `@SpyBean` to wrap any existing bean with a Mockito `spy`.
5802
5802
See the {spring-boot-test-module-api}/mock/mockito/SpyBean.html[Javadoc] for full details.
5803
5803
5804
+
NOTE: CGLib proxies, such as those created for scoped beans, declare the proxied methods as `final`.
5805
+
This stops Mockito from functioning correctly as it cannot mock or spy on `final` methods in its default configuration.
5806
+
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.
5807
+
This allows Mockito to mock and spy on `final` methods.
5808
+
5804
5809
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.
5805
5810
5806
5811
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