spy on the instance variable and return the value when the instance function is called

In the test, you create a spy, and stub some behaviour. But you don’t use that spy in the code under test.

Instead, in the code under test you create a new AuthenticationSessionManager.

You need to restructure your code and:

  • create AuthenticationSessionManager outside of object under test.
  • pass it to object under test. Constructor is the first thing that comes to mind.

With these changes, it becomes trivial to substitute a real AuthenticationSessionManager with a spy in a test.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top