• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

problem installing junit

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a search on junit and some ranch hand said that the XP processing etc., was the best place to post junit questions. So, here I am.
My installation directory for junit is c:\junit3.
I tried the first test and got the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner ...
What could I be doing wrong?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you don't have junit.jar in your classpath when running the tests?
 
Kevin Knowles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, I followed the installation instructions and copied the classpath to my system environment.
set classpath=%classpath%;INSTALL_DIR\junit3\junit.jar
P.S. - I'm using WindowsXP.
[ June 25, 2003: Message edited by: Kevin Knowles ]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that should have been:
set classpath=%classpath%;c:\junit3\junit.jar
INSTALL_DIR is just a symbol indicating that you should use whatever directory you installed into.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the testing forum.
 
Kevin Knowles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Frank Carver
sheriff
Member # 27
posted June 26, 2003 03:01 AM
--------------------------------------------------------------------------------
I'm guessing that should have been:
set classpath=%classpath%;c:\junit3\junit.jar
INSTALL_DIR is just a symbol indicating that you should use whatever directory you installed into


Right, I tried that two.
When I type in "set classpath=%classpath%;c:\junit3\junit.jar" on the command line and <enter> then when I run the tests the window or dialogue boxes come up for the 2nd and 3rd tests, but it says it can't find the tests in the dialogue boxes. In addition, in JBuilder9, it says the test files designated in the package can't be found (or resolved I think).
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess you need to add another ";." to the end of the classpath:
set classpath=%classpath%;c:\junit3\junit.jar;.
so it will find your classes in/under the "current directory" (.) too.
 
Kevin Knowles
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Frank Carver
sheriff
Member # 27
posted June 26, 2003 08:40 AM
--------------------------------------------------------------------------------
I guess you need to add another ";." to the end of the classpath:
set classpath=%classpath%;c:\junit3\junit.jar;.
so it will find your classes in/under the "current directory" (.) too.


Thanks, Frank, but that doesn't work either.
What else should I try?
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell us a bit more about where your class files have been compiled to, and what the "current directory" is set to when you run JUnit?
The bottom line is that all of:
  • the JUnit jar
  • the directory containing your compiled class files
  • any other jars used by your program


  • must be in the classpath somehow.
     
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    With Windows XP, setting the value of an environment variable at a command prompt only affects that command prompt window - it doesn't affect the OS as a whole.
    [ June 26, 2003: Message edited by: Dirk Schreckmann ]
     
    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 Kevin Knowles:
    My installation directory for junit is c:\junit3.
    I tried the first test and got the following error message:
    Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner ...
    What could I be doing wrong?


    I notice that in a later message you mention JBuilder. Are you trying to run tests from JBuilder or from a command prompt.
    If you are getting this error from the command prompt, I suggest you download JWhich from http://clarkware.com. Then use it to see where junit.textui.TestRunner is (not) coming from.
    If you are getting this error from within JBuilder, see how to add external jars to the classpatch JBuilder uses.
     
    Kevin Knowles
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Reply to:
    Richard Jensen
    ranch hand
    Member # 49873
    and others
    I downloaded JWhich and tried to run it, but basically it's the same problem until I change to the C:\JWhich directory where I installed it, but it still says it can't find the AllTests class. I suppose this is the class I should be looking for. I've just been trying to test junit from the command line. If change directory to C:\junit3\junit\samples and try to run the 3 samples, I get the same error message as before. From JBuilder9 the error messages (unresolved classes as I remember) in the test *.java files have gone away. I suppose that is good, but the junit test files don't seem to run right until I enter the classpath definition from the command line.
    I son't know how to use the test files yet anyway, they were just given to me as part of the project package I'm trying to work on.
     
    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
    First, copy JWhich.class into the directory where you installed junit, and make that your current working directory.
    I installed JUnit in C:\junit3.8. And it looks like:

    My classpath variable is set to: C:\junit3.8\junit.jar;C:\ant-1.5\lib\optional.jar;.
    You shouldn't need the ant entry, but notice that I have the junit.jar and '.' in the classpath.
    Now, I execute:

    From the same directory I try:

    So, since I know (since I've run them) that AllTests IS on my computer, why didn't it show up?
    I don't have the fully qualified package.

    So, UNLESS I run my tests from the C:\junit3.8 directory, AllTests is not going to be found because C:\junit3.8 is not in my classpath.
    If I want to run AllTests, I should do it from C:\junit3.8.

    So, assuming your environment is similar, at what point do you get different results than what I've shown?
    [ June 26, 2003: Message edited by: Richard Jensen ]
    [ June 26, 2003: Message edited by: Richard Jensen ]
     
    Kevin Knowles
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Reply to:
    Richard Jensen
    ranch hand
    Member # 49873
    All right, well, my user variables for Kevin are:
    variable | value
    --------------------------------------------------
    set classpath | %classpath%;c:\junit3\junit.jar;.
    set path | C:\windows\system32;%j2sdk1.4.1_03%\bin;c:\windows\system32;%c:\ant%\bin; (note: I'm not sure this is supposed to be here. It just showed up so I added the ant path to it too. I should prbably delete it.)
    System Variables:
    variable | value
    --------------------------------------------------
    set ANT_HOME |c:\ant;
    set classpath|%classpath%;c:\junit\junit.jar;.
    set JAVA_HOME|c:\j2sdk1.4.1_03;
    set path |%path%;%ANT_HOME%\bin;.
    -------------------------------------------------
    Note: There are other a few other setttings in the above, but these are the ones pertaining to this thread.
    The following are the results I get:


    As I said before, if I manually set the classpath for junit from the Command Prompt and run the Java junit tests I get a Frame/window, but I can't tell about the results because there is a message at the bottom saying it can't find the AllTests or whatever.
     
    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
    Somehow some detail got left out of my previous post. The first code section is the content of the directory where JUnit is installed, and I said to make sure that JWhich.class was copied to that directory (and confirm by the output from dir which is what I showed). I'll fix that up.
    As to your CLASSPATH settings, if you do 'set CLASSPATH<return>', you should get back a fully substituted value (that is, there should not be any %var% entries). Like so:

    So, with JWhich.class in the directory in which you installed JUnit, (and with that being your working directory) what are your results for:
  • java JWhich JWhich
  • java JWhich junit.tests.AllTests
  •  
    Kevin Knowles
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    All right, Richard, I copies JWhich.class to my C:\junit3 directory and from the console prompt switched to that directory. Here is what I got:

    and

    and

    By the way, for some reason my "system" must not be accepting the classpath I set in the environment variable, because when I type
    C:\junit3>Classpath
    I get the following:
    c:\junit3>classpath
    'classpath' is not recognized as an internal or external command, operable program or batch file.
    c:\junit3>
    beside results from JWhich doesn't return a classpath.
    P.S.- When I set classpath, this is what I get back:

    [ June 26, 2003: Message edited by: Kevin Knowles ]
     
    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

    Originally posted by Kevin Knowles:


    OK, we're part of the way there. As you note, your environment doesn't have the correct CLASSPATH, so junit.jar isn't appearing in it and since the main of junit.test.AllTests depends on classes in that jar it won't execute.
    So, which version of Windows are you on and how are you setting CLASSPATH? I'm on Windows 2000 and I have the following environment variable set up in the "System variables" section rather than the "User variables for rjensen" section:
  • ANT_HOME C:\ant-1.5
  • JUNIT_HOME C:\junit3.8
  • CLASSPATH %JUNIT_HOME%\junit.jar;%ANT_HOME%\lib\optional.jar;.
  • So, whenever I open a command prompt window this classpath is already set for me.
     
    Kevin Knowles
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok, well I've partly solved the problem.
    I have been following the junit and ant installation instrutctions. However, I am using WindowsXP (as I thought I stated previously), so I suppose that is part of the problem. For example, instead of entering set classpath= etc
    (which is what I tried to do) I needed to enter (in my environment variable settings) variable classpath and under Value
    ".;%classpath%;c:\junit3\junit.jar;." (I read after doing some searches that I need the ".;" first in the classpath definition) and then at the prompt I need to type in set classpath and it sets the classpath for me. However, for ant and java I wound up putting the home paths in the path variable. Maybe I should define the ant_home and Java_home in the variable settings and use a batch file to set those and take them out of the path setting. What would you suggest?
     
    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

    Originally posted by Kevin Knowles:
    Ok, well I've partly solved the problem.


    That's great, which part is still giving you problems?

    I have been following the junit and ant installation instrutctions. However, I am using WindowsXP (as I thought I stated previously), so I suppose that is part of the problem. For example, instead of entering set classpath= etc
    (which is what I tried to do) I needed to enter (in my environment variable settings) variable classpath and under Value ".;%classpath%;c:\junit3\junit.jar;." (I read after doing some searches that I need the ".;" first in the classpath definition) and then at the prompt I need to type in set classpath and it sets the classpath for me.


    OK, I booted up my WinXP (home edition) laptop and installed JUnit and set my JUNIT_HOME environment variable via the Control Panel->System->[Advanced] stuff. I put JUNIT_HOME in the System variables part and CLASSPATH in the User variables part. Now when I start a command prompt the variables are set. If I run:

    from the install directory I get some errors, but for the most part it works.

    on XP I'm using 1.4.1_01 (build b01) and I think there are some known problems with Java/XP. I haven't really looked into it.
    I don't think you need to put '.' first in your CLASSPATH (I didn't). And "set CLASSPATH" doesn't set the environment variable, it shows the current value. You can even do things like "set PA" to find the values of all of the environment variables starting with PA.
    Let me know if you have other problems getting JUnit going.
     
    Kevin Knowles
    Ranch Hand
    Posts: 45
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, the only problem I'm having now is with ant.
    from the command prompt:

    I don't understand why it keeps giving me the warning: JAVA_HOME environment variable is not set, because I've set the JAVA_HOME variable inside windows and again with my SetJavaEnv.bat file. The junit tests work fine now.
     
    Ranch Hand
    Posts: 127
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I read previous messages above and no body mentioned about creating a batch file for compiling and running JUnit. I didn't set JUNIT_HOME in Eviromental variables of your Operating System. I just set it into the batch files itself. well, my compileTest.bat file for compiling a test class is:
    echo off
    echo set JUnit_Home variable
    set JUNIT_HOME=c:\junit3.8.1
    echo compile test classes
    javac -d classes -classpath .;%JUNIT_HOME%\junit.jar myPackage\test\MyTestFileTestCase.java
    echo compiling finished
    Now, to run the test:
    echo off
    echo set JUnit_Home variable
    set JUNIT_HOME=c:\junit3.8.1
    echo run test classes
    java -classpath .;%JUNIT_HOME%\junit.jar;c:\mainFolder\unit\classes junit.textui.TestRunner myPackage.test.MyTestFileTestCase
    echo run test classes finished
    echo terminate manually
    pause
    Now, about your problem with setting Ant, I think the problem with ANT_HOME. set ANT_HOME into enviromental variables of your Operating System as:
    ANT_HOME=c:\ant2
    set your path as:
    %ANT_HOME%\bin;.
    the same thing for JAVA_HOME or even for JUNIT_HOME
    I didn't set classpath into eviromental varaibles of my Operatin System. I always set it within my batch files.
    Qusay
     
    What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic