Monday 29 October 2018

Noob on testing, what should I test for?

I've read a bunch of stuff and watched a bunch of videos and everyone says talks about writing your (failing) test first, before making one line of code. Then write your unit to make the test succeed. Ok good. But what should I test for?All the examples that I saw do something like this. Suppose I need a function that sums 2 numbers.First thing we should write the failing test. Something like this:var res = sum(2,3);expect(res).to.equal(5);Then write the function:function sum(x, y) {return x + y;}Now the test would succeed. But is this enough? Is that it?Shouldn't I test, for example, for wrong argument types? What if someone passes 2 strings instead of 2 numbers to the function? What about arrays? Or Objects? Should I test for that case (and expect an error or something like that)? Where and when do you stop?

Submitted October 29, 2018 at 09:08AM by honestserpent

No comments:

Post a Comment