• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Junit generator...

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XDoclet can do this quite easily.
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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-
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Eclipse IDE also has functionality to do this.
reply
    Bookmark Topic Watch Topic
  • New Topic