I am new to unit testing, and would like to know how you would go about unit testing a procedure (in this case a procedure a function that “does something” rather than “return something”.
I know that the general idea of testing a function that returns an answer is something like
assert(yourfunction(sample, inputs) == expected_answer);
but am wondering how this would work if something does not return or merely returns a status code.
You need to be able to test what it does. For example, does your procedure add something to a collection? Set a property? Create a file?
Whatever it is, presumably that change is visible somehow. You just need to work out how to check that effect. Of course, that can be easier said than done sometimes, which is why a functional approach is easier to test when it’s suitable 🙂 In particular, effects which modify external resources (the file system, databases etc) and effects which depend on external resources (ditto) are harder to test than those which only change things in a fairly “local” way.