1

I have a folder with the following subfolders and files

proj
    src
        Class.java
    test
        Test.java

The file Test.java issues an import org.junit.* command, and uses the class in Class.java.

I've compiled Class.java. I'm now trying to compile Test.java. While in the proj/test folder, I tried the following and several variations on it:

javac -cp ../src org.junit Test.java

and I get several errors, all related to the fact that it's not finding org.junit and Class.java. For instance

error: package org.junit does not exist

and in reference to a class in Class.java:

error: cannot find symbol

The nearest that I've found to my question are about running a test from the command line, but this seems to have already successfully compiled and this one but it has a .jar file, which I don't have and I suspect I shouldn't be making one just now. Also because I'm not using .jar files, this question does not apply to my problem.

Addem
  • 3,635
  • 3
  • 35
  • 58
  • https://stackoverflow.com/questions/2235276/how-to-run-junit-test-cases-from-the-command-line – shakeel Nov 19 '17 at 08:02
  • @shakeel That doesn't answer my question, as I'm not using .jar files. The commands in the answer don't work when I execute them, as I indicated in the question. – Addem Nov 19 '17 at 22:10
  • It does answer your question clearly. java -cp /absolute/path/for/compiled/classes:/absolute/path/to/junit-4.12.jar org.junit.runner.JUnitCore your.package.TestClassName "I get several errors" -> yes you need to include those jar files in classpath to get rid of errors. – shakeel Nov 20 '17 at 06:40
  • @shakeel And yet it still doesn't work, so apparently that solution isn't a solution for me. It uses `java` whereas my scripts have not even compiled yet. If I change it to `javac` it still doesn't compile, even after adding the jar files to the classpath. – Addem Nov 20 '17 at 18:15
  • I suggest you add ***all*** the extra info you posted in your comments into your answer, and tidy up the last paragraph a little bit. Hopefully, that *might* get your question reopened. – robinCTS Nov 21 '17 at 03:33
  • In that case i would suggest to elaborate the errors you receive when you compile(after including jar files). That's first step . Also share the command you use to compile and how you include jar files. – shakeel Nov 21 '17 at 05:02

0 Answers0