Member-only story
Making Assertions On A Stub For Consecutive Calls
When you need to write some unit tests for a piece of code like the following one, you need to make sure that the dependencies are called expectedly on each call in case of repetitive calls like recursion.
As you can see in the example code above, the method returns the parsed response if the page count equals the current page, otherwise, it calls itself recursively. So, in case of recursion, we need to make sure that the method and the mocked dependencies are called with the correct parameters on each call in the tests.
Requirements:
We need some dependencies for the example project.
Creating Stubs and Dummy Objects
As the recursion case occurs when thex-total-pages
key from the response headers is received with a value bigger than one, we can start to write out test code by creating dummy…