From b53f54f2cfc59bc044ff43f997bf8bfeb050089b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 5 Aug 2020 18:24:34 +0100 Subject: [PATCH] Add tip about using AopTestUtils.getTargetProxy with proxied spy beans Closes gh-22281 --- .../src/main/asciidoc/spring-boot-features.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index dfbdf29ed5..0a6ea49143 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -6286,6 +6286,9 @@ NOTE: While Spring's test framework caches application contexts between tests an 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`. This ensures that the parameter names are available to the caching infrastructure once the bean has been spied upon. +TIP: When you are using `@SpyBean` to spy on a bean that is proxied by Spring, you may need to remove Spring's proxy in some situations, for example when setting expectations using `given` or `when`. +Use `AopTestUtils.getTargetProxy(yourProxiedSpy)` to do so. + [[boot-features-testing-spring-boot-applications-testing-autoconfigured-tests]]