Ok, let’s assume that I have a function that checks to see which is the most repeated number in a given array.
This function then needs to be tested, and, need to be tested using particular values in order to make sure that the function worked correctly (Unit testing) – What are these values? I’m confused.
P.s Why should I need to use these values, why couldn’t I just debug the code, or, write it on pen and paper to see what the result SHOULD be and then match it against the value outputted?
Corner cases.
*Can it handle negatives *
How does it handle ambiguous cases
How does it handle arbitrarily large ints
How does it handle arbitrarily large Arrays
How does it handle nulls
Why units test and not just debug ?
1.) debugging assumes you know there error is there already. If we always knew about all errors just by looking at the code we wouldn’t need to test at all would we?
2.) Often times we are more interested in the undefined areas of a functions spec then the errors in the code. You never told me how you handle null values in the array… You’ll need to specify that in your spec before your api is ‘complete’
3.)For this particular function working it out by hand is easy. But what if you are computing the determinate of the jacobian matrix of a function? You don’t really want to do that on paper do you?
4.) In an enterprise environment formalized testing prevents teams from cutting corners during crunch times, which can be very damaging to companies, and net sum will increase development time rather then decrease it due to reduced stability in code.