The Artima Developer Community
Sponsored Link

Java Answers Forum
How to do JUnit Testing in Java

2 replies on 1 page. Most recent reply: Oct 23, 2008 6:50 AM by Jesper de Jong

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jessy Zhang

Posts: 2
Nickname: mydreams
Registered: Aug, 2008

How to do JUnit Testing in Java Posted: Aug 16, 2008 12:29 AM
Reply to this message Reply
Advertisement
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!


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: How to do JUnit Testing in Java Posted: Aug 18, 2008 10:37 PM
Reply to this message Reply
> 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.

Jesper de Jong

Posts: 6
Nickname: 56437
Registered: Jun, 2008

Re: How to do JUnit Testing in Java Posted: Oct 23, 2008 6:50 AM
Reply to this message Reply
If you search Google for "junit tutorial" you will find a number of interesting websites, including tutorials for using JUnit in Eclipse, for example:

http://www.laliluna.de/eclipse-junit-testing-tutorial.html
http://open.ncsu.edu/se/tutorials/junit/

Flat View: This topic has 2 replies on 1 page
Topic: java virtual machine could not find main class Previous Topic   Next Topic Topic: setCurrentDirectory from a string?????

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use