Even if you add all the methods automatically how would you specify the the assert statements to test whether your tests pass the criteria?
Main Topics
Browse All TopicsIf I build a JUnit test class for a particular class and then later add
methods to the class being tested, is there any way to automatically
generate test methods in the test class for the new methods? It looks like
this has to be done manually.
Also, it would be nice if there was some way to validate a test class to
ensure that all public methods are being tested. Can this be done now in
Eclipse Galileo?
Thanks,
KP
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Good point, a_b. The approach I mentioned would really only be useful if you are testing that no exceptions are thrown or you want to get traces from all method executions to determine logical accuracy of your class. I use that for item availability for example as I can run a set of test cases that examining the results lets me determine if all is working correctly, but is manual review of the output by item.
It looks like I didn't express myself very clearly!
I am trying to find out if there is a way to use the Eclipse IDE to generate stub methods for testing all methods that have not already been implemented in the test class. When you first create a JUnit test class in Eclipse it generates stubs for all the methods that need testing at that time but later there may be more methods added to the class being tested that require more methods in the test class. Ideally want I want is to be able to validate a test class to determine if it is testing all the public methods of the class being tested, otherwise the testing is not complete.
My question is then can this be done in Eclipse or is it something that I need to request as an enhancement?
Sorry if I was unclear in my original question. When I referred to generating of the methods in the test class I actually meant generation of the stubs.
Don't know of a way to do that sorry. Might need to be an enhancement request if no one chimes in with the secret. One workaround is to rename the existing YourClassTest class and the regenerate YourClassTest by clicking on new JUnit Test Case with YourClass highlighted and then replace the already implemented methods from your old YourClassTest and then implement the new ones. Not great, but a workaround until another method is found OR even better may be create a YourClassTest2 for the new methods only.
Business Accounts
Answer for Membership
by: mwvisa1Posted on 2009-09-16 at 20:10:31ID: 25352554
Not sure if this is the best way, but could handle both concerns by trying reflection.
ooks/tutor ial/reflec t/
http://java.sun.com/docs/b
M-1