0

I am trying JUnit 4.11. I wrote this sample provided at JUnit FooTest.java

public class FooTest{

  @Test
  public void thisAlwaysPass(){
  }

}

I have the JUnit 4.11 jar and the Hamcrest jar at /usr/lib/jvm/java/jre/lib/ext

Now when I run the following command, it says that it is unable to find the class.

$ java -cp . org.junit.runner.JUnitCore FooTest
JUnit version 4.11

could not find class : FooTest

Time : 0.002

OK (0 Tests)

I thought there is some problem with the classpath. So I tried without JUnit, and it said that main is missing:

$ java -cp . FooTest
Error: main method not found in FooTest

So Java is able to load the class. But when I try to run with JUnit, it cannot find the class. I have a basic understanding of the java class loading. Am I missing something here with JUnit?

I am using Fedora 17 & OpenJDK 1.7

durron597
  • 31,968
  • 17
  • 99
  • 158
ferosekhanj
  • 1,086
  • 6
  • 11

1 Answers1

0

What I guess is that. FooTest is not in the classpath. Try this

java -cp pathtojunit\junit-4.11.jar;pathtohamcrest\hamcrest.jar;pathto\FooTest.class; 
orj.junit.runner.JUnitCore FooTest

Or You can put all your jars and your test class in one folder say c:\junittest\ and try this

javac -cp c:\junittest\*; FooTest.java
java -cp c:\junittest\*; org.junit.runner.JUnitCore FooTest
rozar
  • 1,058
  • 3
  • 15
  • 28
  • No its is available in the current folder. I am passing the "." to -cp – ferosekhanj Aug 01 '14 at 03:37
  • So you have all the junit and FooTest and hamcrest in one folder and you are running your command from that folder? Because what cp does is it overrides the javaclass path – rozar Aug 01 '14 at 17:49
  • with the above command and steps I was able to run the unit test for the FooTest class in my computer. – rozar Aug 01 '14 at 17:49