question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

spy() serializable support

See original GitHub issue

check 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:open
  • Created 7 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
LouHubiaocommented, Oct 18, 2017

mock(class, withSettings() .serializable() .spiedInstance(object) .defaultAnswer(CALLS_REAL_METHODS));

3reactions
sanjutoyoucommented, Jun 9, 2017

Its a much needed feature for classes using spark and other related frameworks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found