Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I become "test infected" with TDD? [closed]

I keep reading about people who are "test infected", meaning that they don't just "get" TDD but also can't live without it. They've "had the makeover" as it were. The question is, how do I get like that?

like image 581
Andrew Harmel-Law Avatar asked Sep 06 '08 17:09

Andrew Harmel-Law


People also ask

What is the correct TDD cycle?

There are 5 steps in the TDD flow: Read, understand, and process the feature or bug request. Translate the requirement by writing a unit test. If you have hot reloading set up, the unit test will run and fail as no code is implemented yet.


3 Answers

Part of the point of being "test infected" is that you've used TDD enough and seen the successes enough that you don't want to code without it. Once you've gone through a cycle of writing tests first, then coding and refactoring and seeing your bug counts go down and your code get better as a result, not only does it become second nature like Zxaos said, you have a hard time going back to Code First. This is being test infected.

like image 115
MattGrommes Avatar answered Nov 10 '22 01:11

MattGrommes


You've already read about TDD; reading more isn't going to excite you.

Instead, you need a genuine personal success story.

Here's how. Grab some code from a core module, code that doesn't depend on external systems or too many other subroutines. Doesn't matter how complex or simple the routine is.

Then start writing unit tests against it. (I'm assuming you have an xUnit or similar for your language.) Be really obnoxious with the tests -- test every boundary case, test max-int and min-int, test null's, test strings and lists with millions of elements, test strings with Korean and control characters and right-to-left Arabic and quotes and backslashes and periods and other things that tend to break things if not escaped.

What you'll find is.... bugs! At first you might think these bugs aren't important -- you haven't run into these problems yet, your code probably would never do this, etc. etc.. But my experience is if you keep pushing forward you'll be amazed at the number of little problems. Eventually it becomes hard to believe that none of these bugs will ever cause a problem.

Plus you get a great feeling of accomplishment with something is done really, really well. We know code is never perfect and rarely free of bugs, so it's nice when we've exhausted so many tests that we really do feel confident. Confidence is a nice feeling.

Finally, I think the last event that will trigger the love will happen weeks or months later. Maybe you're fixing a bug or adding a feature or refactoring some code, and something you do will break a unit test. "Huh?" you'll say, not understanding why the new change was even relevant to the broken test. Then you'll find it, and find enlightenment. Because you really didn't know that you were breaking code, and the tests saved you.

Hallelujah!

like image 45
Jason Cohen Avatar answered Nov 09 '22 23:11

Jason Cohen


Learn about TDD to start, and then begin integrating it into your workflow. If you use the methodologies enough, you'll find that they become second nature and you'll start framing all of your development tasks within that framework.

Also, start using the J-Unit (or X-Unit) framework for your language of choice.

like image 27
Zxaos Avatar answered Nov 09 '22 23:11

Zxaos