| Author |
Junit on Eclipse
|
rick collette
Ranch Hand
Joined: Mar 22, 2002
Posts: 208
|
|
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 ]
|
 |
Richard Jensen
Ranch Hand
Joined: May 14, 2003
Posts: 67
|
|
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
N 37 33 W 122 18
|
 |
Richard Jensen
Ranch Hand
Joined: May 14, 2003
Posts: 67
|
|
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".
|
 |
David Weitzman
Ranch Hand
Joined: Jul 27, 2001
Posts: 1365
|
|
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
Joined: Mar 22, 2002
Posts: 208
|
|
Thanks, Richard and David: You guys are a lot of help! I will look into your excellent suggestions.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Junit on Eclipse
|
|
|