Unable to verify spy behavior when spying on proxy
See original GitHub issueWhen spying on a proxy instance (discovered with springs @Transactional
), Mockito’s verify(mock) method, will nearly always return successful even when the expectations are absurd.
I wrote this test to demonstrate the unexpected behavior: Test of Spying on Proxy
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Mockito - spying on real objects calls original method
In this case Mockito proxy is not being executed. I would like to keep existing CGLIB decoration and still be able to use...
Read more >Mockito - Using Spies - Baeldung
In this tutorial, we'll illustrate how to make the most out of spies in Mockito. We'll talk about the @Spy annotation and how...
Read more >Mockito' spy() method and Spring - A Java geek
This magic method creates a proxy (hence the name spy) on a real object. It delegates its method calls to the proxied object...
Read more >Mockito 4.1.0 API - javadoc.io
Spying on real objects. You can create spies of real objects. When you use the spy then the real methods are called (unless...
Read more >Top 12 Mockito Interview Questions (Mocking Framework ...
Answer: Spy is a type of partial mock supported by Mockito. ... But it still allows you to verify the interactions with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So instead of :
spy(proxy)
usemock(TestSubject.class, delegatesTo(springProxy))
.However if annotations are need to read, then you’ll need mockito 2 beta. Because mockito 1.x uses CGLIB which doesn’t copies annotations on the mockito subclass. Mockito 2 uses the great bytebuddy.
This doesnt seem to work. I am using below powermockito version