0

Is it possible to execute JUnit test on a jar file, I created earlier?

I tried:

java -cp myJarFile.jar org.junit.runner.JUnitCore myPackage.myClass

and

java -cp myJarFile.jar org.junit.runner.JUnitCore myPackage.myClass.myMethod

and

 java -cp myJarFile.jar:path/to/junit-4.11.jar org.junit.runner.JUnitCore myJarFile.jar myPackage.myClass

I'm getting an error: Could not find class: myPackage.myClass

The method is annotated by @Test

Joel
  • 1,725
  • 3
  • 16
  • 34
  • https://stackoverflow.com/questions/2235276/how-to-run-junit-test-cases-from-the-command-line – Matthias J. Sax Jul 14 '15 at 22:00
  • I found it, read it, tested it, and have that error. For me it seems like they do not use their own compiled project, but the sourcefiles. – Joel Jul 14 '15 at 22:03
  • It seems `junit.jar` is missing in your classpath. – Matthias J. Sax Jul 14 '15 at 22:05
  • also fails with the same error. – Joel Jul 14 '15 at 22:08
  • Can you post the concrete command? What is the content of your jar file? – Matthias J. Sax Jul 14 '15 at 22:20
  • The jar contains a main(String[] args) array and several packages, classes. Beside, there is a testclass, which has some methods annotated with `@Test`. I can perfectly use `eclipse` to `run as JUnit test`. This is the concrete command. I just shortened the paths. – Joel Jul 14 '15 at 22:25
  • Just looked at your posted commands more closely. The first two, are missing `junit.jar` in classpath. The third has `myJarFile.jar` a second time after `JUnitCore`. You need `java -cp myjar.jar:junit.jar org.junit.runner.JUnitCore myPackage.myClass` (without `.class` in myClass) – Matthias J. Sax Jul 14 '15 at 22:33
  • how do i now, which classes are inside the 'jar', if i just have the 'jar' file? – Joel Jul 16 '15 at 20:16
  • 1
    `jar tf ` list all files contained (look into the manual for details) – Matthias J. Sax Jul 16 '15 at 20:31

0 Answers0