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
2010-03-03 08:55:14
I have already added this : -java () -classpath () path to project/bin org.junit.runner.JUnitCore package.classs
2010-03-03 08:58:02
@lamisse `java` and `javac` are two different programs - see my update.
Péter Török
2010-03-03 09:00:07
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 ?
2010-03-03 09:00:29
so in my command line I should have -javac (path to java bin) -classpath() org.junit.runner.JUnitCore package.classs ?
2010-03-03 09:02:29
@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
2010-03-03 09:02:46
@lamisse see my example and link
Péter Török
2010-03-03 09:14:48
peter , javac -cp(all external jar) my_test.java -d /generate_class
2010-03-03 09:52:57
is the above line ok ?
2010-03-03 12:14:41
@lamisse Looks OK to me - does it do work in your environment?
Péter Török
2010-03-03 12:28:59
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 ?
2010-03-04 15:43:27
@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
2010-03-04 16:11:21
@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
2010-03-04 16:12:33
????? when answers will be also suitable
2010-03-04 20:31:35
@lamisse OK, your decision... good luck for it
Péter Török
2010-03-04 21:00:23
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
2010-03-03 08:56:58