spy() serializable support
See original GitHub issuecheck that
- The mockito message in the stacktrace have useful information, but it didn’t help
- The problematic code (if that’s possible) is copied here; Note that some configuration are impossible to mock via Mockito
- Provide versions (mockito / jdk / os / any other relevant information)
- Provide a Short, Self Contained, Correct (Compilable), Example of the issue (same as any question on stackoverflow.com)
- Read the contributing guide
This is an issue for the latest version. Support serializable() for the mock() is a great feature!
According to the source code. spy also uses mock()
Why don’t you support mockSetting argument for spy()
like below code snippet? Is there any problem when it comes to call .serializable()
with .spiedInstance()
public static <T> T spy(T object, MockSettings mockSettings) {
return MOCKITO_CORE.mock((Class<T>) object.getClass(), mockSettings.withSettings()
.spiedInstance(object)
.defaultAnswer(CALLS_REAL_METHODS));
}
val spyMyObject = spy(myObject, witSettings.serializable())
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
MockSettings (Mockito 3.2.4 API) - Javadoc.io
Configures the mock to be serializable with a specific serializable mode. MockSettings · spiedInstance(Object instance). Specifies the instance to spy on.
Read more >Serializable mocks (Since 1.8.1) - Mockito 中文 - CWIKI.US
To create serializable mock use MockSettings.serializable() : ... Making a real object spy serializable is a bit more effort as the spy(.
Read more >MockSettings (Mockito 2.2.7 API)
Configures the mock to be serializable with a specific serializable mode. MockSettings · spiedInstance(Object instance). Specifies the instance to spy on.
Read more >Mockito verify not working with serialized/deserialized mock
This serialization & deserialization means a new instance of the mock is created and that's where the interaction happens so when I'm calling ......
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Also note that the methods equals() and hashCode() cannot be mocked. Creating Spies. To create a spy, you need to call Mockito's static...
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
mock(class, withSettings() .serializable() .spiedInstance(object) .defaultAnswer(CALLS_REAL_METHODS));
Its a much needed feature for classes using spark and other related frameworks.