Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I start using TDD on a project that doesn't use it already

Tags:

tdd

I have a project that I have been working on for a while, just one of those little pet projects that I would like to one day release to open source.

Now I started the project about 12 months ago but I was only working on it lightly, I have just started to concentrate a lot more of my time on it(almost every night).

Because it is a framework like application I sometimes struggle with a sense of direction due to the fact I don't have anything driving my design decisions and I sometimes end up making features that are hard to use or even find. I have been reading about how to do TDD and thought maybe this will help me with some of the problems that I am having.

So the question is do you think it's a good idea to start using TDD on a project that doesn't already use it.

EDIT: I have just added a bit to clarify what I mean by struggle with a "sense of direction", it properly wasn't the best thing to say without clarification.

like image 811
Nathan W Avatar asked Nov 17 '08 04:11

Nathan W


People also ask

Why TDD is not usually used?

This means the following problems in such a TDD approach: More test code than the implementation code. Not easy to design tests before the implementation is done. Implementation refactoring breaks existing tests.

Do people actually use test driven development?

Test driven development has become popular over the last few years. Many programmers have tried this technique, failed, and concluded that TDD is not worth the effort it requires. Some programmers think that, in theory, it is a good practice, but that there is never enough time to really use TDD.

Does TDD really lead to good design?

TDD does not necessarily lead to good design. It's possible and really easy to get poorly designed program using TDD. TDD is just a tool to help us design faster using refactoring, it will never make the design of the program appear magically. TDD is a design help tool.


2 Answers

In my opinion, it's never too late to adopt a better practice - or to drop a worse one - so I'd say "Yes, you should start".

However ... (there's always a "but") ...

... one of the biggest gains of TDD is that it impacts on your design, encouraging you to keep reponsibilties separate, interactions clean and so on.

At this point in your project, you may find it difficult to get tests written for some aspects of your framework. Don't give up though, even if you can't test some areas, your quality will be the better for the areas you can test, and your skills will improve for the experience.

like image 132
Bevan Avatar answered Sep 19 '22 04:09

Bevan


Yes.

Basically, you can't do any harm by adding TDD for any new code you write, and any changes you make to existing code. Obviously it would be tricky to go back and retro-fit accurate tests to existing code, but it certainly couldn't hurt to cover the primary use-cases.

Maybe consider having a look at Brownfield Application Development in .NET? It is full of pragmatic and practical advice for exactly this scenario (one of the definitions offered for "Brownfield" is "without proper unit tests").

like image 28
Marc Gravell Avatar answered Sep 20 '22 04:09

Marc Gravell