views:

807

answers:

13

Hello, I have been reading quite a bit recently about TDD and such and I'm not quite sold on it just yet.. I make a lot of small hobby projects(just me) and I'm concerned if trying to do TDD is overkill for such a thing. Though I have seen small open source projects with like 3 developers that do TDD. (though I have seen a few one-person projects that also do TDD)

So is TDD always a good thing to do or at what threshold does it make sense to use?

+24  A: 

TDD shines in small projects. It's often much easier to adhere to TDD in a small project, and it's a great time to practice and get the discipline required to follow TDD.

In my experience larger projects tend to be the ones that abandon TDD at some threshold. (I'm not suggesting this is a good thing).

I think larger projects tend to abandon it for a couple of reasons:

  • Developer inexperience --- either in general or with TDD
  • Time Constraints --- Larger projects are inherently more complex
    • Added complexity leads to deadline overruns and unit tests tend to get ditched first
    • This can be exacerbated by an inexperienced team
hobodave
+1 A friend of mine tried to introduce TDD in a quite large company, and while they ackowledged the benefits, the stuck to the widely used code and fix model ^^.
Helper Method
Another reason it is abandoned: not spending the needed time refactoring the tests themselves. Test code gets smelly fast! If you don't stay up on this aspect then changes to underlying structures can have big cascading effects. Anyway, go for it!
roufamatic
@roufamatic: totally true. Just like code tends to decay over time, tests do, too, and writing unit tests that are maintainable takes practice (usually starting by not doing it right, and learning the hard way). On top of that, I have seen a few people hesitating to refactor tests, as if tests were sacred.
Mathias
+1: Time Constraints == Management's Refusal to Embrace Change. Too often, it's management that insists that folks stop testing and just start writing code.
S.Lott
+4  A: 

I would take the opportunity of using TDD with a small project just to get your feet wet. It would be a good learning experience even if you realize it's not for you.

JimDaniel
+1  A: 

When you think that consequential errors that you don't expect might happen as a result of your writing code, TDD makes sense.

lance
+3  A: 

I believe it's worth it for most any project. TDD and the consequent regression testing enables you not only to determine if components work as you write them, but as you introduce changes and refactorings. Provided your tests are sufficiently complete, you can cover scenarios for infrequent/unlikely edge cases and produce/maintain more reliable code.

Going forwards through the project lifecycle, the continuous testing cycles will save you the manual repetition of tests, and negate the obvious chance of repeating these incorrectly/incompletely.

Brian Agnew
+4  A: 

Overkill? Not at all. In addition to the main benefit, which is writing code you can rely on because you've thought about ways it can break, you'll be more disciplined and potentially more productive with test driven development. Pick up any of the Pragmatic Programmer books for tips and inspiration.

Oleg
+1  A: 

Well, it is not really the amount of people that is the deciding factor for TDD (at least this is what your question kind of infers), but much rather the size of the project.

Advantages of TDD are, that all the code you are developing will pretty much be unit-tested. That way you save a lot of hassle when refactoring later. Of course this is really just necessary when your project has a decent size.

Sebastian Hoitz
+10  A: 

Everything has a cost-benefit curve.

Ignoring many of the oft' disputed benefits of TDD, TDD is worth it if your implementation will change sufficiently often that the benefit of having an automated test suite outweighs whatever extra cost might be involved in initial development.

Kaleb Pederson
+2  A: 

I and others use TDD on any project that is more than say a few lines of code.

Once you get the testing bug, it's hard not to use TDD for anything. Personally I've found my code has improved several times over due to TDD.

Finglas
+1: TDD made me lazy. Writing tests is easy. Once written, then some code to pass the test is often better understood because of the process of writing the tests.
S.Lott
+26  A: 

Small Projects can have a habit of turning into big projects without you realizing, then you wish you'd started with TDD :)

Fraser Graham
A: 

I'd say it totally depends on the given time frame. If you've got the time to spend almost twice the time you'd usually require, then go for it. But in my opinion speed is these days one of the most important factors (for competitive companies).

n00b
"usually require"? Do you mean the time required to produce code with no testing? Code in which you have no evidence that it works? How is that "usual"? It sounds awful.
S.Lott
uhm... no. I mean with "usually" the time you'd need to develop something with your informal testing procedures...
n00b
Does this "usually require" include the time for writing the informal test plans and procedures and the time required to rework it when the tests fail? Or is the "usually require" the time required only to type the code without actually doing any testing?
S.Lott
it means the first of your versions
n00b
I'm amazed that the time "usually" required to do informal testing and rework is somehow less than the time required to do TDD. I've never observed that in practice. Informal testing seems to take forever after the code is written. Indeed, I've seen projects cancelled because they could not be tested through this informal test and rework process. I guess your informal testing is really fast and really accurate. That's amazing. I'd like to know more about how you get informal testing done so quickly and accurately. Do you have a blog where you could post your experiences.
S.Lott
i'm sorry my fiends... i didn't claim i'm right. you are probably. i sure have some caching up to do to compete with your 30 years devel exprience :) anyway, thanks for you halfway constructive criticism!
n00b
@JaZz: I'm curious about the "almost twice the time" part of your answer. Can you provide some evidence for TDD taking twice as long as manual testing? You may have good information, can you share it?
S.Lott
+8  A: 

I always find a question like this funny. What is the alternative? Writing code that you only compile and never run to verify its correctness? Do you wait until you deploy to production to find out if your class works at all?

If we never had a practice called TDD, or before JUnit was invented back in 1997, was there no code testing? Of course there was. So why is it such a big deal now that you have testing frameworks to help you with this?

Even a small project on a tight deadline won't want to wait until production to find out if it works. Write the tests.

It's not necessary for any project that's "small", but I define "small" as less than one class.

duffymo
I think there are two alternatives that make the question reasonable (rather than funny): (1) manually testing, and (2) writing automated tests after the fact, rather than before.
Kaleb Pederson
Honestly, I don't see that TDD is much more work than either (1) or (2) - hence the humor.
duffymo
+1: TDD vs. what? "Manual" testing? Does that mean incomplete tests done by people you hope are clever enough to find ways to exercise all class interface through the external interface. Tests after the fact -- based on the as-implemented code? I can't see that these are viable alternatives. Just because I've been on projects that attempted this (for over 30 years now) doesn't make them viable alternatives.
S.Lott
+3  A: 

Something I've heard from one member of our local Agile group is that she doesn't find TDD useful for the very earliest stages of the project, where you're essentially making quick sketches and you're not really sure what shape the thing is taking yet. But as soon as you have some ideas of what the interfaces look like, you can start using tests to help you define them.

TDD is another tool, like documentation, to improve the clarity of the code. This is critical when other people need to work with your code, but many of us find it's also very helpful when looking back at our own code. Ever had a hobby project you picked back up after being away from it for a while, came across a weird bit of code, and wondered "why the heck did I write that?"

keturn
+4  A: 

From my personal experience I can say the following:

  1. Every single time I started one of my personal little hobby projects, I vowed to develop it using TDD.
  2. Every single time I didn't.
  3. Every single time I regretted it.
Jörg W Mittag