|
|
Re: How to do JUnit Testing in Java
|
Posted: Aug 18, 2008 10:37 PM
|
|
> I am interested in JUnit Testing, but I am a novice. I > have no idea how to da Unit Testing in Java in Eclispe > Environment. Would you like to give me some advice and > guide? Thanks a lot!
I'm using RAD (which is built on top of Eclipse), not sure if Standard Eclipse comes with a JUnit plugin but if you do have your Eclipse Plugin installed. Follow this process:
1) Right Click the Source Folder in which you want to write your Unit Test, surf to New -> Other. (I think the equivalent Hot key to this is Ctrl + N - while focus is on the folder, I stand to be corrected) 2) There should be a Java JTree menu. Expand it then Expand the JUnit box the click on JUnit Test Case. You will get a straight forward wizrard.
when you are all done you should have a class to looking like this:
import junit.framework.TestCase;
public class SomeTestCase extends TestCase {
}
You may want to override methods like teardown if you are running persistence tests then you will want to clean up your database after persisting.
I usually create a new source folder called test at the same level as my application source code (src), remember to add this as source for the project and remember to exclude it in your distributable application Jar, War or Ear.
When you want to run it obviously you just right click it and run it as a JUnit App.
Hope this helps.
|
|