• Post Reply Bookmark Topic Watch Topic
  • New Topic

Junit generator...  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I assume, everybody here is familiar with junit. We write test method for each public method for all the classes that are in project, except getter-setter methods.

What I would like is to make a program that generates *empty* test method for each public method of all classes.

I mean, program will take classes one by one, search for public method, if found, will make a test class for that class and finally will make empty test method for that method.

I hope I am clear with my requirements.

So please give me some inputs how should I proceed...

Thanks a lot.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, the input for the program will be path of workspace...
Now the program will find java source in that... then program will scan each package and then each class............

Could any please tell me which API does something like this...

Thanks.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XDoclet can do this quite easily.
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
I assume, everybody here is familiar with junit. We write test method for each public method for all the classes that are in project, except getter-setter methods.


If XDoclet doesn't serve your needs, this would be a reasonably simple program to implement yourself. Iterate all classes on the classpath, ignoring test classes; use the reflection API to derive the methods (see the Class method getDeclaredMethods); iterate each method, ignoring methods starting with "get", and check each method to see if it's public (use getModifiers).

There are of course products that do a much more comprehensive job for you, that attempt to create the entire set of unit tests. You might take a look at Agitar or Parasoft.

Note that a one-to-one relationship between a test method and a production method isn't what you always want. Often you may require multiple test cases to completely exercise a given production method.

Another alternative is to consider the use of test-driven development, in which case the process is reversed--you write the test, then have your IDE (Eclipse, IDEA both do this) generate the production stub code.

-Jeff-
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Eclipse IDE also has functionality to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!