tags:

views:

252

answers:

3

in the java test I have :

package Tester.GUI.api
public class Test1{-----}

in the ".bat" :

<path to java> -classpath<all jar defined in the classpath separated by ";"> org.junit.runner.JUnitCore Tester.GUI.api.Test1

when I launch th ".bat" I have the following :

JUnit version 4.6
Could not find class: Tester.GUI.api.Test1
Time: 0,203

OK (0 tests)

I have verified jar files , typo but not found the cause someone could help please?

A: 

The -classpath option needs to take a set of directies and/or jar files. Currently those are missing, so your main class (JUnitCore) is being used as the classpath, and Test1 used as the main class. I'm guessing you want JUnitCore as the main class and Test1 as the argument.

Try something like this (substituting the actual names of the jars you're using for jar-file1, jar-file2):

java -classpath <jar-file1.jar>;<jar-file2.jar> org.junit.runner.JUnitCore Tester.GUI.api.Test1

Edit: Assuming jar files are specified correctly, the error message indicates that the Test1 class isn't on the classpath. If you're using an IDE, you need to find the output directory for compilation (for example, in Eclipse it is <project>/bin by default). Within this directory you will find other directories with the structure Tester/GUI/api. A file called Test1.class will be in the api directory. It is this output directory that needs to be added to the classpath (that is, the one above the Tester/GUI/api structure).

Ash
I have not mentionned the jar files because I have many jar, it is already specified in the -classpath , shuld I add something in the .classpath file in the src? add java test class name?
laura
You may also be able to omit the `-classpath` option entirely if your system is already set up to include all of the needed jar files in the `CLASSPATH` environment variable. In that case, your command would just be `java org.junit.runner.JUnitCore Tester.GUI.api.Test1`.
Joe Carnahan
@laura: .classpath (you're using Eclipse or some other IDE?) will have no effect from a .bat file. It sounds purely like your `Test1` class isn't being found on the classpath. @Joe's suggestions should help you track it down (for example, add `;bin/` to your classpath list if you're using, say, Eclipse with the default output folder of `bin`). Basically, you want to add the folder that your test classes are being compiled to.
Ash
@Ash - You bring up a good point: The important thing is where the complied .class files are, not where the .java source files are. If you're using an IDE (as the mention of ".classpath" would suggest), then those won't be the same by default.I've already edited my answer accordingly. :-)
Joe Carnahan
A: 

It says that the class that it cannot find is Tester.GUI.api.Test1. What directory are you running the test from, and what directory is your Test1 code in?

If you set the -classpath variable, you may also need to include the current directory in your classpath. So, if your original command was

java -classpath C:\foo.jar;D:\bar1\bar2.jar org.junit.runner.JUnitCore Tester.GUI.api.Test1

you could add the current directory to your classpath by adding ;. to the end of your -classpath option like this:

java -classpath C:\foo.jar;D:\bar1\bar2.jar;. org.junit.runner.JUnitCore Tester.GUI.api.Test1

This will work as long as the Test1 class is in the Tester\GUI\api directory under the current directory.

The tricky thing with setting the classpath in Java is that you don't want to give the directory where your actual .java files are, but instead you want to give the directory under which you can find the directories that are named for the packages in your code.

For example, if I compiled a class Foo in a package bar.baz, then I should have a file named Foo.class in a directory named baz inside another directory named bar. If I want to include Foo in my classpath, and if Foo.class is located at C:\Users\Joe\Code\bar\baz\Foo.class, then I have to either run

java -classpath C:\Users\Joe\Code [main class goes here]

or else I have to change my directory to C:\Users\Joe\Code and run

java -classpath . [main class goes here]
Joe Carnahan
I do not understand :should I add to class path :-java -classpath C:\foo.jar;C:\api\Test1;. org.junit.runner.JUnitCore Tester.GUI.api.Test1
laura
I can give a much more precise answer if you could answer these two questions: 1. In what directory is your `.bat` file being run? 2. In what directory is `Test1.class`?If you don't know where `Test1.class` is, then I still might be able to help if you could tell me where `Test1.java` is and how you compiled `Test1.java`. For example, did you use an IDE like Eclipse to compile `Test1`, or did you use the `javac` command in a batch file or at the command prompt?
Joe Carnahan
A: 

now, my java test doesn't work from eclipse whereas it worked yesterday : when I run java the following popup : no junit tests found

This doesn't look like an answer to this question - Maybe you meant this as a comment on the question that you asked here? http://stackoverflow.com/questions/2332832/
Joe Carnahan