Looking at TDD from newbie’s point of view
Preface
Many times heard people says that test is vitally important for software developing and kinds of test methodology,after have been developing Java web application for over a year,I deeply realized that test is the combination of experience and technology. Last Friday I accepted JUnit training,the training showed us TDD and the teacher shared his experience of test,it is excellent. Now I will share what I learnt recently.
What is TDD?
TDD is abbreviation of Test-Driven Development,is a core technology of XP (eXtremely Programming),but this methodology can do many help for testing our software even though it not being developed in XP process. Here you may doubt what XP is,I would tell you just Google it.
XP philosophy
Any methodology has its own philosophy,so XP too. Communication,Simplicity,Feedback and Courage are the four values sought out by XP programming. We can see the human character of XP,cannot you?
TDD steps
We can do our TDD by doing the following steps:
First,understand and simplify the requirements
Second,think over you test-driven and complete it
Third,complete your business classes or methods which are being tested by your test-driven
Finally,run you test-driven and make the test pass
If the requirements were changed,just do the same steps mentioned above
If the code smells bad,refactoring your code.
Actually,here refactoring is the most important step,and it need developers experienced. We may ask what is refactoring,there is a book--- Refactoring by Martin Flow showed us what it really is.
Why it is better?
Now we might have seen that TDD is not only for test,but also for design. It is better for the following reasons:
First,most programmer would prefer code to documents,and the test-driven is a good idea to solve the problem.
Second,test-driven make programmer do their work confidently. They can test they code any time and have the reason believe that the code is right.
Yes,they must be more,but the first statement in this section is enough. TDD is not only for test,but also for design.
Some rules
First,developers must write test-driven for his(or her) class or methods.
Second,write test-driven for classes or methods you believe must be tested not all methods or classes.
Third,run you test-driven any time and make your code clean.
Forth,refactoring your code if it looked ugly anytime.
Mr. Robert C. Martin showed us his rules:
You are not allowed to write any production code unless it is to make a failing unit test pass.
You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
See more and detail on his site,there is a link in the bibliography of this article.
Using JUnit in TDD
Keep the bar green to keep your code clean,it is JUnit. It is a tool gives us the ability to write our test-driven conveniently. Reduce percent of mistakes in our test-driven. It is easy to use and make our test-driven develop more efficiently. Of course,JUnit is not enough,there are kinds of auto-tools can work with JUnit. Just find out our Mr. right.
Using JUnit in out-sourcing
Condition is special in out-sourcing development,especially in out-souring for Japanese,here developers have been deprived their last freedom. When we make our decision use JUnit to test our program,the following questions should have been thought over carefully.
First,get agreement of JUnit from our customer.
Second,customer would like to pay for test-driven
Third,customer wouldn’t mind there are no test documents
Forth,make sure our team has the energy and experience
Fifth,test is for experienced member,not newbie
Six,for GUI test,auto-test won’t work any longer
Experiences
Auto test is a lie for lazy developers,anytime and anywhere,men will be ever the core. Think everything over carefully.
Summary
I am afraid the article a bit off topic,but I don’t think it won’t do any harm to the goal of showing experience on testing. There is nothing can be absolutely depended on except our self,our knowledge,our experience and our intelligent mind.
Bibliography
http://www.butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
http://blog.csdn.net/rmartin/archive/2006/08/17/1089322.aspx
http://www-128.ibm.com/developerworks/cn/linux/l-tdd/