Reputation: 1657
I am trying to run a JUnit 4 test from commandline. This is my current command:
java -cp C:\Users\some\.m2\repository\junit\junit\4.11\junit-4.11.jar junit.textui.TestRunner C:\Some\Path\target\test-classes\com\wicket\range\ui\MyTest.class
This gives a class not found error.
I have also tried the following:
C:\Some\Path\target\test-classes>java -cp C:\Users\some\.m2\repository\junit\junit\4.11\junit-4.11.jar junit.textui.TestRunner com.wicket.range.MyTest.class
This also gives a class not found error; what could be the issue here?
Upvotes: 0
Views: 154
Reputation: 2826
Looks like you are using Maven (saw the ".m2" in your classpath). How about this..
cd <location of pom.xml>
mvn -Dtest=MyTest test
Granted it may be a while until before it runs your test and it's not going to use JUnit's text ui runner, but it should run your test without much fuss about ClassNotFoundException. Examine files in target\surefire-reports for test results afterwards. Guess it depends on exactly what your goal is.
Otherwise, Jayan's answer looks about right to me. For his to work, I think you want to first
cd C:\Some\Path\target\test-classes
Upvotes: 1
Reputation: 18459
I assume your test class is under C:\Some\Path\target\test-classes (in appropriate subdirectory). Your command has only junit in it. It also need class path to the test and other dependencies.
Try
java -cp C:\Some\Path\target\test-classes;C:\Users\some\.m2\repository\junit\junit\4.11\junit-4.11.jar junit.textui.TestRunner com.wicket.range.MyTest.class
Upvotes: 2