I want to run Junit from commandline in Mac OS but Im not able to get it to work as expected with a simple test class that I have created.
I have downloaded junit-4.12.jar
for this purpose and been writing a very simple test class with one simple test method.
Im running with the following command to compile the class:
javac -cp .:/Full/path/to/junit/junit-4.12.jar DemoTest.java
..and running the following command to execute the compiled class:
java -cp .:/Full/path/to/junit/junit-4.12.jar org.junit.runner.JUnitCore DemoTest
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class DemoTest {
@Test
public void evaluate(){
assertEquals(true, 1<2);
}
}
I'm expecting to see "test pass" when I am running the junit class from commandline, because that's what it should generate. Instead Im getting the following error message (please note that Im only pasting the first line of error for the sake of simplicity):
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Does this mean that Im only missing the hamcrest.jar
file to be able to run the application as expected?
Please let me know if you need the complete error stacktrace!
As the error message
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
mentioned you miss the hamcrest-core
library in your class path. Download it and add it to the classpath
java -cp .:/Full/path/to/junit/junit-4.12.jar:/Full/path/to/hamcrest/hamcrest-core-1.3.jar org.junit.runner.JUnitCore DemoTest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.