Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I Use TDD?

I'm the only developer in my (very small) company and I'm about to start on a medium sized ASP.NET web application for said company.

I'm trying to figure out if I should learn Test Driven Development (TDD) and implement it in this application.

I need to start developing our new application shortly and I'm worried about testing. I've programmed for many years but have never done any unit testing.

I've read numerous online resources regarding TDD but I'm unsure whether I'll have a 'good enough' grasp on it to make it effective in the application.

like image 414
CalebHC Avatar asked May 27 '09 18:05

CalebHC


2 Answers

It depends on where your priorities lie. If you're interested in furthering yourself as a developer, TDD is definitely worth looking into if only for the experience. It'll help you rethink the way you code and probably make you a better developer because of it.

But that could easily be outweighed by how much TDD hampers your ability to get your product out in a timely manner. You mentioned that you're the only developer working at this company and that means that the pressure is on you to get your project done. TDD is certainly a great practice, but sometimes real life constraints and practicality must come first.

So in short, if you can spare the time then yes, use TDD. It's actually not that much overhead and you can always skip the testing in a pinch. But if you're really strapped for time and don't think you'll be able to incorporate it without putting your product and job at risk, nobody would fault you for skipping it. The purists will disagree, but it's not a black and white world and sometimes compromises must be made to get things done.

like image 171
Kevin Pang Avatar answered Sep 21 '22 19:09

Kevin Pang


Remember this: the only bad test is the one you don't execute.

Now, do you need to dive directly into TDD? Maybe not. But you should definitely start unit testing whatever you can. You can't unit test GUIs very well, and that's fine -- save those for UAT.

But any sort of logic you might execute behind the scenes? Yep, you should test it.

Start by just trying to test individual methods. As you go you'll start running into pain, because most likely your code isn't designed to be tested. This is fine; refactor your code! Keep doing so until you can test your code. Remember what you had to do and do that the first time the next time you write code.

After a few iterations, you'll learn what you need to learn (really, you can only learn it by doing) and the pain will go away. When that happens, I'd suggest you're probably ready to look into TDD.

like image 31
Randolpho Avatar answered Sep 18 '22 19:09

Randolpho