How to auto generate unit testing code in Java
General Description :
We all familiar with the unit testing phrase.
In the continuous integration world this phrase became a must.
Although sometimes , to write quality unit testings takes more time than to write the real code.
Code Coverage is a well known phrase in the software developing world.
Some will say that Code Coverage should allways be 100%, I really don’t think so , it takes a lot of work to maintain the 100% , and it doesn’t worth it.
According to some continuous integration development articles written by team leaders probably ,
The optimized ratio of code Coverage is about 80%.
In order to achive this ratio you need some discipline from your developers , or you can use the CodePro eclipse plugin !
CodePro’s solution :
Google have published a new Eclipse plugin which can auto generate unit testing classes and methods based on your buisness logic !
all you have to do is install the plugin , adjust the settings (or use the default ones , it doesn’t matter) and run the Auto Generate command right from eclipse!
So , How to Auto Generate the JUnit classes ?
- in Eclipse -> go to help->install new software (how to install new plugins from Eclipse’s update manager) and insert the link (http://dl.google.com/eclipse/inst/codepro/latest/3.7).
- Right click on your project , CodePro Tools->Generate Test Cases.

- And that’s it !
of course , if you like to change the package of you test cases from the default (as default it creates a new project with a “Test” suffix) you can do it by clicking CodePro->Preferences->JUnit->Auto Generation and change the settings there.


