Loading ...
Sorry, an error occurred while loading the content.

Setting up JUnit on Mac OS X Panther

Expand Messages
  • lindbird9
    I am trying to fix the Class Path for JUnit so I can run some tests by way of Ant. I have been to many sites on setting the path, but have come up with the
    Message 1 of 4 , Apr 2 12:36 AM
    View Source
    • 0 Attachment
      I am trying to fix the Class Path for JUnit so I can run some tests
      by way of Ant. I have been to many sites on setting the path, but have come up with the
      same result. I even followed a previous post to no avail.

      I have unziped junit3.8.1 into Applications/Utilities/Java

      I have gone into my .bashrc file and added:
      CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/
      junit3.8.1/junit.jar:/Applications/
      Utilities/Java/junit3.8.1
      export CLASSPATH

      or

      export CLASSPATH=$CLASSPATH:/Applications/Utilitie
      s/Java/junit3.8.1/junit.jar
      export CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/junit3.8.1/

      ...I have tried both ways.
      After saving and opening a new shell, I try and run a test:

      java junit.swingui.TestRunner junit.samples.AllTests

      ...and I get:
      Exception in thread "main" java.lang.NoClassDefFoundError:
      junit/swingui/TestRunner

      I guess that it could not find the class listed. Next I just try to
      make the file through Ant,
      and get the following errors:

      test:
      [javac] Compiling 3 source files to /Users/ryan/SE450/hw1-src/build/classes
      [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:1:
      package junit.framework does not exist
      [javac] import junit.framework.Assert;
      [javac] ^
      [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:2:
      package junit.framework does not exist
      [javac] import junit.framework.TestCase;

      ...I assume this is also from not finding the classes.

      I have run out of ideas and am wondering if anyone can help. I don't
      think there is anything special to be done when unzipping it... I think my problem
      is in the class path

      I don't know if this helps, but my .tcshrc file looks like this:
      setenv JAVA_HOME /Library/Java/Home
      setenv ANT_HOME /usr/local/ant
      setenv PATH /usr/local/ant/bin:$PATH

      Thanks for any help,
      Ryan
    • Jason Rogers
      I believe you need to have the junit.jar in $ANT_HOME/lib ... -- Jason Rogers Where there is no vision, the people perish... Bible, Proverbs 29:18
      Message 2 of 4 , Apr 2 7:03 AM
      View Source
      • 0 Attachment
        I believe you need to have the junit.jar in $ANT_HOME/lib

        On Fri, 2004-04-02 at 08:36, lindbird9 wrote:
        > I am trying to fix the Class Path for JUnit so I can run some tests
        > by way of Ant. I have been to many sites on setting the path, but have come up with the
        > same result. I even followed a previous post to no avail.
        >
        > I have unziped junit3.8.1 into Applications/Utilities/Java
        >
        > I have gone into my .bashrc file and added:
        > CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/
        > junit3.8.1/junit.jar:/Applications/
        > Utilities/Java/junit3.8.1
        > export CLASSPATH
        >
        > or
        >
        > export CLASSPATH=$CLASSPATH:/Applications/Utilitie
        > s/Java/junit3.8.1/junit.jar
        > export CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/junit3.8.1/
        >
        > ...I have tried both ways.
        > After saving and opening a new shell, I try and run a test:
        >
        > java junit.swingui.TestRunner junit.samples.AllTests
        >
        > ...and I get:
        > Exception in thread "main" java.lang.NoClassDefFoundError:
        > junit/swingui/TestRunner
        >
        > I guess that it could not find the class listed. Next I just try to
        > make the file through Ant,
        > and get the following errors:
        >
        > test:
        > [javac] Compiling 3 source files to /Users/ryan/SE450/hw1-src/build/classes
        > [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:1:
        > package junit.framework does not exist
        > [javac] import junit.framework.Assert;
        > [javac] ^
        > [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:2:
        > package junit.framework does not exist
        > [javac] import junit.framework.TestCase;
        >
        > ...I assume this is also from not finding the classes.
        >
        > I have run out of ideas and am wondering if anyone can help. I don't
        > think there is anything special to be done when unzipping it... I think my problem
        > is in the class path
        >
        > I don't know if this helps, but my .tcshrc file looks like this:
        > setenv JAVA_HOME /Library/Java/Home
        > setenv ANT_HOME /usr/local/ant
        > setenv PATH /usr/local/ant/bin:$PATH
        >
        > Thanks for any help,
        > Ryan
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        --
        Jason Rogers

        "Where there is no vision, the people perish..."
        Bible, Proverbs 29:18
      • Chappell, Simon P
        Yes. This is true. The reason is to do with classloaders. Both Ant and JUnit employ their own custom classloaders and they don t play well together! (There is
        Message 3 of 4 , Apr 5 8:34 AM
        View Source
        • 0 Attachment
          Yes. This is true. The reason is to do with classloaders. Both Ant and JUnit employ their own custom classloaders and they don't play well together! (There is a long technical reason, but it's Monday morning, so "don't play well together" will have to do for now. ;-)

          Simon "the mighty Mac user" Chappell


          >-----Original Message-----
          >From: Jason Rogers [mailto:jacaetevha@...]
          >Sent: Friday, April 02, 2004 9:03 AM
          >To: junit@yahoogroups.com
          >Subject: Re: [junit] Setting up JUnit on Mac OS X Panther
          >
          >
          >I believe you need to have the junit.jar in $ANT_HOME/lib
          >
          >On Fri, 2004-04-02 at 08:36, lindbird9 wrote:
          >> I am trying to fix the Class Path for JUnit so I can run some tests
          >> by way of Ant. I have been to many sites on setting the
          >path, but have come up with the
          >> same result. I even followed a previous post to no avail.
          >>
          >> I have unziped junit3.8.1 into Applications/Utilities/Java
          >>
          >> I have gone into my .bashrc file and added:
          >> CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/
          >> junit3.8.1/junit.jar:/Applications/
          >> Utilities/Java/junit3.8.1
          >> export CLASSPATH
          >>
          >> or
          >>
          >> export CLASSPATH=$CLASSPATH:/Applications/Utilitie
          >> s/Java/junit3.8.1/junit.jar
          >> export CLASSPATH=$CLASSPATH:/Applications/Utilities/Java/junit3.8.1/
          >>
          >> ...I have tried both ways.
          >> After saving and opening a new shell, I try and run a test:
          >>
          >> java junit.swingui.TestRunner junit.samples.AllTests
          >>
          >> ...and I get:
          >> Exception in thread "main" java.lang.NoClassDefFoundError:
          >> junit/swingui/TestRunner
          >>
          >> I guess that it could not find the class listed. Next I just try to
          >> make the file through Ant,
          >> and get the following errors:
          >>
          >> test:
          >> [javac] Compiling 3 source files to
          >/Users/ryan/SE450/hw1-src/build/classes
          >> [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:1:
          >> package junit.framework does not exist
          >> [javac] import junit.framework.Assert;
          >> [javac] ^
          >> [javac] /Users/ryan/SE450/hw1-src/source/InventoryTEST.java:2:
          >> package junit.framework does not exist
          >> [javac] import junit.framework.TestCase;
          >>
          >> ...I assume this is also from not finding the classes.
          >>
          >> I have run out of ideas and am wondering if anyone can help. I don't
          >> think there is anything special to be done when unzipping
          >it... I think my problem
          >> is in the class path
          >>
          >> I don't know if this helps, but my .tcshrc file looks like this:
          >> setenv JAVA_HOME /Library/Java/Home
          >> setenv ANT_HOME /usr/local/ant
          >> setenv PATH /usr/local/ant/bin:$PATH
          >>
          >> Thanks for any help,
          >> Ryan
          >>
          >>
          >>
          >>
          >>
          >> Yahoo! Groups Links
          >>
          >>
          >>
          >>
          >--
          >Jason Rogers
          >
          >"Where there is no vision, the people perish..."
          >Bible, Proverbs 29:18
          >
          >
          >
          >------------------------ Yahoo! Groups Sponsor
          >---------------------~-->
          >Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
          >Printer at MyInks.com. Free s/h on orders $50 or more to the
          >US & Canada.
          >http://www.c1tracking.com/l.asp?cid=5511
          >http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/5cFolB/TM
          >---------------------------------------------------------------
          >------~->
          >
          >
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
        • Demyanovich, Craig - Apogent
          Simon, Thanks for the explanation of your classloader woes. I ve never used the CLASSPATH environment variable on any system on which I ve worked. I have an
          Message 4 of 4 , Apr 6 5:51 AM
          View Source
          • 0 Attachment
            Simon,

            Thanks for the explanation of your classloader woes. I've never used the
            CLASSPATH environment variable on any system on which I've worked. I have
            an ANT_HOME environment variable, and junit.jar is in ANT_HOME\lib so that
            the junit task will work.

            My project layout includes a lib folder, into which I place a copy of
            junit.jar. I then reference junit.jar and other 3rd party libraries like
            this in Ant:

            <!-- ================================================================= -->
            <!-- Defines the compilation classpath for the project -->
            <!-- ================================================================= -->
            <path id="classpath.compilation">
            <fileset dir="${basedir}/lib">
            <exclude name="junit.jar" />
            </fileset>
            </path>
            ...
            <!-- ================================================================= -->
            <!-- Defines the compilation classpath for the project's tests -->
            <!-- ================================================================= -->
            <path id="classpath.compilation.test">
            <pathelement location="${basedir}/build/classes/prod" />
            <fileset dir="${basedir}/lib" />
            </path>

            As I said, I've never had a problem executing a test from Ant. Furthermore,
            I haven't devised this scheme that I use in order to avoid any problems.
            Perhaps I was simply fortunate to find a way that worked without ever having
            to troubleshoot classloader problems.

            Thoughts?

            Thanks,
            Craig

            <<<<<<<<<<<<< >>>>>>>>>>>>>
            Craig Demyanovich
            Software Developer
            Apogent Technologies, Inc.
            Tel: 269-544-7514
            Fax: 269-544-7409
            cdemyanovich @ apogent dot com
          Your message has been successfully submitted and would be delivered to recipients shortly.