In the program, the same object sequentially, from different arguments, returns different values, depending on which branching occurs. In the test, it is impossible to override the mock so that it returns a different result to the second call. How to be in this situation?

    1 answer 1

    Use ->at() or your own callback for the set expectation'а :

    • Yes, great, at () works. While doing with callBack, it also happened, but I could not pass parameters to it. The parameters from the real function are transferred there, but how to pass the parameters from the test? - nMike
    • @nMike (IMHO) - If you write correctly, then the callback should decide only on the basis of its input parameters. - If it turns out some more complicated logic or additional data is required, then they should be put into private members of the test class or create an auxiliary object of the type `TestCallbackFactory. - Costantino Rupert
    • Well, according to the logic, callback is called with the parameters that you pass to it. In this case, your parameters from the test are ignored, instead of them there are parameters from the function being tested (that is, those that are passed to the muffled method when it is called from the function being tested). - nMike