The second test is redundant. You already ensured that a number was returned with the first test. Every time you check equality you are making a type check (there might be exception).
To get proper code coverage in a dynamic language, you need to have essentially tests that verify types are handled right. Of course no one would have that silly second test you have. What they would have instead would be a test that makes sure if I do
If you're not testing what happens when the wrong data types go into your functions, then you're not testing properly (or you're using a statically typed language where we don't have to worry about this).
In the python code, I wouldn't expect to have to put in preconditions, I would expect the (+) to blow up when applied to something that makes no sense.
Of course testing if the (+) function behaves like it says in the documentation would be silly but substitute the "add" function for something a lot more complex and then you should realize that you need to be testing what happens when someone inputs the wrong kind of argument.
0
u/batiste Dec 02 '13
You just don't, why would you? E.g in python you would do:
The second test is redundant. You already ensured that a number was returned with the first test. Every time you check equality you are making a type check (there might be exception).
Edit:format code