views:

51

answers:

2

hello I wrote a java test and I run it from run as junit test in my project a bin folder was created with ".class" file when I wrote a shell to launch the same test(with some modif) by command line it it launches the test without taking account my modif , do the tests use tha generated .class ? could I remove this ".class" and launch test by command line ? when I launch it by command line,do ".class" generated ? or should I add something to compile test? thanks

A: 

In your script you should add the proper call to javac (the Java compiler) in order to recompile your (source and test) classes, before invoking java (the Java runtime environment) to run your tests. The IDE does this automatically for you.

Provided your test classes are under the test directory, the command to compile your class would look something like this (you may need to add classpath too if you depend on external jars):

javac -sourcepath test *.java -d bin

Here is a reference about the javac parameters on Linux/Solaris, with examples.

Péter Török
I have already added this : -java () -classpath () path to project/bin org.junit.runner.JUnitCore package.classs
@lamisse `java` and `javac` are two different programs - see my update.
Péter Török
my problem is from Linux ,when I launch by command line after removing the generated .class , it says no calss found and I do not understand normally when I launch by command line it compile the test so generate .class associated to the test , non ?
so in my command line I should have -javac (path to java bin) -classpath() org.junit.runner.JUnitCore package.classs ?
@lamisse on command line, after removing the .class files, you must call `javac` to compile your sources again before trying to run them with `java`. Otherwise you will get the aforementioned error.
Péter Török
@lamisse see my example and link
Péter Török
peter , javac -cp(all external jar) my_test.java -d /generate_class
is the above line ok ?
@lamisse Looks OK to me - does it do work in your environment?
Péter Török
yes it works but then, I should be careful when I work in windows or linux environement :from eclipse(windows) tje class are generated automatically by eclipse when I compile the java test if I want to launch the same java test from linux ,I have to add javac before and remove the generated class ,no ?
@lamisse You may not need to remove the .class files completely (although you can, if you want to be on the safe side), but you should call `javac` in any case before running your tests. Eclipse is available on Linux too, btw - maybe it could solve your problem if you used the same IDE on all platforms?
Péter Török
@lamisse Btw your accept rate is 0% - it does not encourage people to answer your posts. Could you go back and accept suitable answers to your previous posts?
Péter Török
????? when answers will be also suitable
@lamisse OK, your decision... good luck for it
Péter Török
A: 

When you run the tests from IDE, your project (java source files) is most likely being automatically compiled before the run. If you want to run it from the command line, you need to compile the sources first using javac.

pajton