Sunday, October 12, 2008

Tips for Unit Test

Today, I would like to recommend 12 tips for Unit Testing to every developer :) .
(A good case study for Unit Test is the Craftsman story, you can read the Vietnamese translation here: http://diendantinhoc.net/?cat=se_craftsman )



Unit Testing is one of the pillars of Agile Software Development. First introduced by Kent Beck, unit testing has found its way into the hearts and systems of many organizations. Unit tests help engineers reduce the number of bugs, hours spent on debugging, and contribute to healthier, more stable software.

In this post we look at a dozen unit testing tips that software engineers can apply, regardless of their programming language or environment.



1/ Unit Test to Manage Your Risk


2/ Write a Test Case Per Major Component


3/ Create Abstract Test Case and Test Utilities


4/ Write Smart Tests


5/ Set up Clean Environment for Each Test


6/ Use Mock Objects To Test Effectively


7/ Refactor Tests When You Refactor the Code


8/ Write Tests Before Fixing a Bug


9/ Use Unit Tests to Ensure Performance


10/ Create Tests for Concurrent Code


11/ Run Tests Continuously


12/ Have Fun Testing!


Probably the most important tip is to have fun. When I first encountered unit testing, I was sceptical and thought it was just extra work. But I gave it a chance, because smart people who I trusted told me that it's very useful.

Unit testing puts your brain into a state which is very different from coding state. It is challenging to think about what is a simple and correct set of tests for this given component.

Once you start writing tests, you'd wonder how you ever got by without them. To make tests even more fun, you can incorporate pair programming. Whether you get together with fellow engineers to write tests or write tests for each other's code, fun is guaranteed. At the end of the day, you will be comfortable knowing your system really works because your tests pass.



(Full credit of this article belongs to Alex Iskold and ReadWriteWeb)

(^o^)

1 comment:

Anonymous said...

sao ben blog Duy Do cung co bai giong giong nhu bai nay