7 Replies Latest reply: Jan 6, 2009 11:19 AM by 796447 RSS

    Junit command line

    807589
      Hello
      I'm trying to start a JUnit test from command line.
      I've succesfully started it with the java org.junit.runner.JUnitCore MyClass
      My problem is that I have my main class in a jar file. The manifest file is pointing to the correct main class but when i use
      the java org.junit.runner.JUnitCore -jar myjarfile.jar i get these messages:
      Couldn't find class -jar
      Couldn;t find class myjarfile.jar
      Is there any other way ?
      Thanks
        • 1. Re: Junit command line
          807589
          The manifest is irrelevant here. So is the jar, really. It should just be a part of your runtime classpath, like Junit is. That is, don't bother using the -jar bit, that's what's causing your problem. Specifically, the JUnit runner is taking that switch as a commandline arg, and trying to load a class called -jar. Same goes for your jar itself.
          • 2. Re: Junit command line
            807589
            What do you mean the manifest is irrelevent?
            I kind of figure out that -jar and jarfile.jar are taken as arguments line (doh)
            I was kind of looking for a replacement for the org.junit.runner.JUnitCore that works with jar files
            • 3. Re: Junit command line
              807589
              this is in some way related to this :
              http://forums.sun.com/thread.jspa?threadID=5308984
              • 4. Re: Junit command line
                807589
                jipada wrote:
                What do you mean the manifest is irrelevent?
                I kind of figure out that -jar and jarfile.jar are taken as arguments line (doh)
                Well they're not arguments that a JUnit runner takes. Doh.
                I was kind of looking for a replacement for the org.junit.runner.JUnitCore that works with jar files
                Figure it out for yourself, your sarcasm has bitten you on the @ss. That runner is perfectly adequate for your needs, by the way
                • 5. Re: Junit command line
                  796447
                  jipada wrote:
                  Hello
                  I'm trying to start a JUnit test from command line.
                  I've succesfully started it with the java org.junit.runner.JUnitCore MyClass
                  My problem is that I have my main class in a jar file. The manifest file is pointing to the correct main class but when i use
                  the java org.junit.runner.JUnitCore -jar myjarfile.jar i get these messages:
                  Couldn't find class -jar
                  Couldn;t find class myjarfile.jar
                  Is there any other way ?
                  Thanks
                  You apparantly do not realize that switches (such as -jar) must be placed before the argument which specifies which class to run.
                  But in this case, a -jar command line option is in direct conflict with a class name to run, because that would mean search the jar file for its manifest to figure out what class to run. You want a -classpath switch, not a -jar switch.
                  • 6. Re: Junit command line
                    807589
                    Sarcasm was the last thing on my mind especially at that moment when I was in need of help, but your message just added to my frustration. I've put the jar file in the classpath and add the main class from the manifest file as the argument for junit runner. It works now. You could of said that cause I kind of suspect you knew. Anyway your messages helped. Thanks
                    • 7. Re: Junit command line
                      807589
                      jipada wrote:
                      Sarcasm was the last thing on my mind especially at that moment when I was in need of help
                      Really? Then I must have misunderstood you. If so, my apologies.
                      but your message just added to my frustration. I've put the jar file in the classpath and add the main class from the manifest file as the argument for junit runner. It works now. You could of said that cause I kind of suspect you knew. Anyway your messages helped. Thanks
                      I did say that. Apart from the "main class from the manifest" bit, which I have no way of knowing, and, in all honesty, is wrong in all but the most simple of cases. Your jar probably consists of more than just the one class, and a fair number of those would be tested, no?

                      Anyways, you got your solution, which is the main thing