views:

276

answers:

5

I am aware of this question: http://stackoverflow.com/questions/428691/how-to-encourage-implementation-of-tdd

In my team, we write a lot of unit tests. But, in general the programmers tend to write unit tests after wrting the code. So, we first finish the module functionality and then write tests. Our coverage is around 70% for most modules. I have tried convincing my technical manager and my team members to do pure TDD wherein we first write tests and then the code, but invain. I think writing tests first allows us to discover design better. Am I just being finicky, especially when our coverage is quite high? If the answer to this question is no, then how do I talk to people to have a test-first approach.

EDIT: I think writing tests after writing code is an easier thing to do. People in my team have got accustomed to do this and are opposing any change.

+4  A: 

To be honest, you should use always just use a development/test cycle that works.

A lot of people like TDD, and a lot of big players like Google have embraced it; because of the high test coverage.

However, it seems that you and your team tend to be doing pretty well without it—and remember, and change in development style decreases productivity at least temporarily. So remember the old adage, don't change what works.

However, if you and your customers are finding that there still are a lot of bugs that the tests don't cover, TDD is an ideal way to up that—so you should tell management that TDD is a way to increase customer satisfaction, thus make money. (That's management-speak for you!)

aharon
+1 for management's concerns
mmsmatt
+11  A: 

I don't know that there is a whole lot you can tell people to convince them of the value of TDD. You can cite what the experts have told us about it, and your own personal experiences, but if folks are not willing to give it a try, chances are low that you sharing this information with them will help.

My experience with TDD was basically that it sounded like a really good idea, but it never really worked out the way it was supposed to. Then one day I tried it again on a new task and ended up with a solution to the problem that was simpler than what I would have thought possible, due entirely to the fact that I had used TDD. I think when developers have this sort of experience it changes the way they look at things, and makes them more willing to try it in other situations.

The challenge is being able to demonstrate this to the other developers. One way you may be able to do this is with the use of a TDD Kata like this one from Roy Osherove (he uses it in his TDD Master Course). It is designed specifically to demonstrate the value in working in small steps, implementing only the code that is needed to make each test pass. This may show folks how the process works, and make them more comfortable with giving it a try.

There was also a coding exercise I heard about where you gave two groups/teams of developers a reasonably simple task, and asked one of the groups to use TDD, and make sure they followed the "simplest thing that could possibly work" rules, while the other team did things however they wanted. Then, once that is done, you have the teams switch tasks, but throw out the code written by each team, leaving only the tests. The teams are then supposed to recreate the code for the task. Typically you will find that the team who inherits the TDD code has a much easier time doing this.

Given all that, though, I think the best thing you can do personally is to start doing TDD yourself for as much of your work as possible. This has the potential to give you some very specific references for where and how TDD has proved to be beneficial within the context of the current project. In particular if you do code reviews your peers may notice the code that you are writing TDD is more concise, and easier to maintain than the code that has been writing without TDD. Your QA team may also notice a difference in the quality of the code, which is one of the things that you hear a lot about companies who move to TDD.

ckramer
+1, this is a good answer. P.S: 'You can **cite** what the experts have told...'
Cam
Thanks for the typo fix @Carl Manaster/@incrediman. It was late when I put that post together...I was headed to bed :)
ckramer
Carl Manaster
+4  A: 

A couple suggestions. Your practicality may vary:

  • Win over one or two people: your boss, an intern, etc, over to your side first. Your first follower will make you a leader.
  • Start pair programming or mentoring. Even if its just with an intern or two, working closely with someone can be a good way to influence their style. If you are willing, you could try becoming a manager.
  • Give a technical presentation on the subject. Make the focus on the why and the problem you are solving, instead of TDD. You want people to buy into the problem rather than your specific solution. Include a couple other alternatives so it doesn't seem like you are just trying to push what works for you.
  • Get some outside training from Object Mentor or the like. Works best if you can convince your boss and the team isn't a bunch of hardened soulless cynics.
Ben Gartner
Your first follower will make you leader...very true. Had seen this before...just didn't strike me this time.
Sandbox
Yes, sometimes I wish getting people to use a better process didn't require a movement, but unless you work with very open-minded people...
Ben Gartner
+1 for the 'first follower' video, it made my day!
Gary Willoughby
+3  A: 

Perhaps Leading by example can help:

Start working like this yourself

Perhaps create a tutorial\script to setup the environment (the IDE) that will not add overhead to the TDD process:

  1. Run the tests in a single keyboard shortcut
  2. The GUI of the test system should be present in the development view (not just in the testing view, so you don't have to move between them)

I am guessing that after a while, people will be curious and ask you if this TDD thing really works, you should have a prepared answer for that question :-)

uvgroovy
+1  A: 

Have you come across BDD at all? There's an associated change in vocabulary which I find really helps newcomers to TDD pick it up. Here's the vocab change:

http://lizkeogh.com/2009/11/06/translating-tdd-to-bdd/

I've found that using this language helps people focus on why it's useful to write the tests (or examples) first. I translated another example in the comments.

Even then, sometimes it's helpful to learn how tests are structured. If people have trouble learning how to write them first, writing them afterwards is a good learning step. You're right about the design benefits. It can take a while to grok.

In the past I've found that the best way to get TDD is to have a safe environment to practice in. Having my own toy app or running / attending workshops based on a toy app have both helped me a lot.

Lunivore