Sometimes we need to stub with different return value/exception for the same method call. Typical use case could be mocking iterators. Another use case that I faced is testing retries.
For example, we are testing a function which makes a network call and on exception, retries once. For testing, we need to mock the network call with two possible outcomes: first it should throw an exception, next time, it should return expected result.
Sometimes we need to stub with different return value/exception for the same method call. Typical use case could be mocking iterators. Another use case that I faced is testing retries. For example, we are testing a function which makes a network call and on exception, retries once. For testing, we need to mock the network call with two possible outcomes: first it should throw an exception, next time, it should return expected result.