vendredi 4 janvier 2019

Does returning a value from a function for unit/integration test have any downsides

Is there a scenario where you would not want to return a value from a function?

Lets say the function I am writing an integration/unit test for looks like this

function functionBeingTested() {
    functionThatIsBeingStubbed();
}

I need to see if functionThatIsBeingStubbed() is getting called and my intuition is that I can just return it, and the value returned will return either true if the arguments pass, or a string that will be the error message if not. Like this;

function functionBeingTested() {
    return functionThatIsBeingStubbed();
}

Is there value in doing this all the time? Is there a scenario where you wouldn't want to return a function that isn't actually needing to be returned for any reason other then testing? Is there a better way? Is returning a string with the error message from the stub a good idea or is there a better way? I am new to testing and am not sure if this is good practice or not.

Aucun commentaire:

Enregistrer un commentaire