• 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 on Eclipse

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am developing a J2EE application on Eclipse, I am using cvs repository. I have also written some test code. The problem is: its really confusing to do JUnit testing on Eclispe. I try to read help content on JUnit, but it is very confusing. For example:


Open the project's build path property page and add the junit.jar contained in the org.junit plugin of your Eclipse install as an external JAR.


It doesn't say where to open the project's buld path. And it does not say how to test using exsisting test classes.
Another thing: it says to select Run > Run as > JUnit Test to do the test, but I do not see Run As under Run from menu, there is only ExternalTools-->Configure. Is something wrong with my IDE?
I am a total newbie on this. Could you guys recommend an easy introduction about this?
Thanks.
[ June 20, 2003: Message edited by: rick collette ]
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rick collette:
It does (not) say where to open the project's buld path. And it does not say how to test using exsisting test classes.
I am a total newbie on this. Could you guys recommend an easy introduction about this?


I'm not aware of any reference, but I am using JUnit in eclipse, so maybe I can help. To set the build path for your project, you can either right-click on the project name and choose Properties or choose Properties from the Project menu (for the currently selected project).
One of the items in the tree is "Java Build Path".
You select the 'Libraries' tab (not the order/export tab) and there you can add the external jars.
Note: adding an external jar is just setting the classpath that will be used to build and run THAT project. Your environment classpath has no effect on this, only the explicit jars here.
The order/export tab allows you to order this classpath. Make sure the junit.jar comes before your source or test directory.
Now, choose the class that has the tests and choose Run->Run As->JUnit test.
 
Richard Jensen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I was a bit hasty on the reference bit. Have you looked in the Eclipse Help under "Java Development User Guide"?
Under "Getting Started" > "Basic tutorial" > "Creating your first Java project" talks about installing the sample JUnit project. Further down in the tutorial it talks about "Writing and running JUnit tests"
Under "Concepts" it talks about the "Build classpath".
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my experience, I find that it's safest and easiest to create a JUNIT_LIB variable (Built Path -> Libraries -> Add Variable -> Edit) and add that to the classpath rather than adding a more specific value.
It's convenient: If you start a new project, you don't have to go seaching for junit.jar in the filesystem or give your app it's own copy of the jar.
It's future-proof: I've got the JUNIT_LIB variable pointed at the eclipse plugins directory, something like "org.junit_3.8.1/junit.jar". When I upgrade to Eclipse 3.0, I can just change the variable to "org.junit_56.2042.-2" and the classpaths for all my projects won't be broken.
It's efficient: There's no point in keeping more than one copy of junit.jar in your filesystem at any given time. There are some .jars that have lots of copies floating around, but junit only belongs in two places on my comp: ANT_HOME/lib and the Eclipse plugins directory. The end-user won't need junit.jar, and the JUnit Ant task won't work unless junit.jar is in ANT_HOME/lib. Releases are all backwards compatable (worst case scenario they'd make a release that wasn't and you could just not upgrade) so the latest version should always be sufficient.
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Richard and David:
You guys are a lot of help! I will look into your excellent suggestions.
 
author & internet detective
Posts: 41914
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Another thing: it says to select Run > Run as > JUnit Test to do the test, but I do not see Run As under Run from menu, there is only ExternalTools-->Configure. Is something wrong with my IDE?


Some things are only available in certain perspectives. Make sure you are in the Java perspective when trying to run the test.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic