PDA

View Full Version : [SOLVED] Problem with running junit



karnpreet
November 10th, 2012, 03:49 PM
Hello,

I made two classes on my school computers named SortArray.java and SortArrayTest,java (being the test file) and it was compiling and working fine on their system, but when I try to compile and do the test on my computer at home it doesn't seem to work. I have Ubuntu 12.10 and have junit all installed. I do the following:-


kevin@ubuntu:~/JavaG/Wk4/Ex2$ javac SortArray.java
kevin@ubuntu:~/JavaG/Wk4/Ex2$ javac -cp /usr/share/java/junit4.jar SortArrayTest.java
SortArrayTest.java:8: error: cannot find symbol
SortArray test;
^
symbol: class SortArray
location: class SortArrayTest
SortArrayTest.java:11: error: cannot find symbol
test = new SortArray();
^
symbol: class SortArray
location: class SortArrayTest
2 errors
kevin@ubuntu:~/JavaG/Wk4/Ex2$ ^C
kevin@ubuntu:~/JavaG/Wk4/Ex2$

Can anyone help me?

ofnuts
November 10th, 2012, 04:51 PM
You explicitly set a class path but it doesn't contain the directory for SortArray.class. Try:


javac -cp /usr/share/java/junit4.jar:. SortArrayTest.java
(I.e., add the current directory to the class path)

r-senior
November 10th, 2012, 04:53 PM
Try adding the current directory to the classpath:


javac -cp .:/usr/share/java/junit4.jar SortArrayTest.java

karnpreet
November 10th, 2012, 05:07 PM
It seems to work but everytime I put


java org.junit.runner.JUnitCore SortArrayTest.java

it just doesn't seem to work as it comes out with the error :-


Error: Could not find or load main class org.junit.runner.JUnitCore

karnpreet
November 10th, 2012, 05:22 PM
This is what happens:-


kevin@ubuntu:~/JavaG/Wk4/Ex2$ javac SortArray.java
kevin@ubuntu:~/JavaG/Wk4/Ex2$ javac -cp .:/usr/share/java/junit4.jar SortArrayTest.java
kevin@ubuntu:~/JavaG/Wk4/Ex2$ java org.junit.runner.JUnitCore SortArrayTest.javaError: Could not find or load main class org.junit.runner.JUnitCore

r-senior
November 10th, 2012, 05:52 PM
Don't you need to specify the classpath again?


java -cp .:/usr/share/java/junit4.jar org.junit.runner.JUnitCore SortArrayTest

karnpreet
November 10th, 2012, 07:23 PM
You are literally a life saver, thank you so much!