Testing has pros and cons (what doesn't?) and it only makes sense to do things when their benefits outweigh the costs. Usually at least. I hope I am speaking for most people here.
Anyway why do I write tests? I write it because it makes a nice todolist. Yeah it gives you that confidence that your program works correctly (does it though?) and refactoring becomes a cinch (I totally remember what ThisClassIMade20DaysAgo does) but I do it for the todolist because I'm forgetful.
Usually before I'm writing the code I imagine writing the code and a lot of times while imagining all of this I come across these edge cases. I obviously don't want to forget them so I write the tests for them. Or at least make empty tests with a descriptive enough name and comments.
So why do you write tests?
Top comments (2)
For many reasons
I guess I missed some reasons but those are my top.
Also, as a side note, when I first started writing tests I wrote tests for the sake of writing tests. I don't know, you just feel better than everyone else. But then I stopped because my fingers started to hurt and it was just tiring really. Point I want to make is that now if I write tests it's just to be sure that my program does what it's supposed to do. I don't care so much if an individual function or class does something wonky as long as the program overall behaves correctly. I think it's impossible to have a misbehaving function or class in a correct program but I haven't really written that many programs anyway.