ShorKy
ShorKy

Reputation: 77

Run Junit Test via command line

Hi first i have already search and saw many post on that on stack overflow and other forum but i can't find any solution X( I would launch a Junit test on command line and without maven first my work folder

->JunitTest
-->.classpath
-->lib
---->hamcrest-core-1.3.jar
---->junit-4.12.jar
-->src
---->sommeClass 
-------->Somme.java (class to test)
---->TestSommeClass
-------->SommeTest.java (class test)

I tried the following command : java -cp lib/junit-4.12.jar org.junit.runner.JUnitCore TestSommeClass.SommeTest

But i have the following error : initializationError(org.junit.runner.JunitCommandLineParseResult) java.lang.IllegalArgumentException: Could not find class [TestSommeClass.SommeTest]

I'm pretty sure that is a problem with my classpath but i tried the SET CLASSPATH command but nothing append in my .classpath file Here my classpath file

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    <classpathentry kind="lib" path="lib/cta-junit-runner-0.0.1-SNAPSHOT-jar-with-dependencies.jar"/>
    <classpathentry kind="lib" path="lib/cta-junit-runner-0.0.1-SNAPSHOT.jar"/>
    <classpathentry kind="lib" path="lib/junit-4.12.jar"/>
    <classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I'm begin with Junit, my test work perfectly in Eclipse and i realy don't find solution to my problem since more than 2 days so please any help would be great ! ^^

Upvotes: 2

Views: 1026

Answers (1)

GhostCat
GhostCat

Reputation: 140407

The point is: when you start a JVM on the command line, you use -cp to tell it about where to find ALL the classes you will later need. As of now, the classpath that you give to the JVM only contains the JUnit JAR.

So how do you think that JVM would be able to load the class under test for example? In other words: everything in your xml snippets that translates to a location where .class files are taking from ... needs to be on your -cp information as well.

Of course, your question doesn't tell us where we would find the compiled classes of your "production" code.

Upvotes: 2

Related Questions