mariofalcao
mariofalcao

Reputation: 61

How to use 'java' command options/arguments when executing JUnit tests

I'm developing a C# application to run JUnit tests automatically. Since it's complicated to move the current location where my C# application is running, i need to execute the JUnit tests without directly go inside their folder.

So, i have this folder tree:

» ProjectFolder

»» ClassesFolder

»» TestsFolder

»»» testX.java

»»» testX.class

I'm already able to compile the files, using:

javac ...\ProjectFolder\ClassesFolder\*.java
javac ...\ProjectFolder\TestsFolder\*.java

But i can't execute the tests. I tried:

java -classpath ...\ProjectFolder org.junit.runner.JUnitCore TestsFolder.testX

And got this error:

Error: Could not find or load main class org.junit.runner.JUnitCore

I even try this way:

java org.junit.runner.JUnitCore ...\ProjectFolder TestsFolder.testX

But, once again, it doesn't work:

JUnit version 4.10
Could not find class: -classpath
Could not find class: ...\ProjectFolder
Could not find class: TestsFolder.testX

Time: 0,003

OK (0 tests)

So, my main doubt, is how i can use the options (like -cp or -classpath) of the java command, when executing JUnit tests using org.junit.runner.JUnitCore.

Thanks in advance.

Upvotes: 1

Views: 316

Answers (1)

Tobb
Tobb

Reputation: 12180

The problem is that the jUnit-runner is not in the classpath you specify. You need to add the path to junit.jar to the classpath.

Google is nice http://www.jsystemtest.org/?q=node/44

But why not just use something that already exists and can take care of this? Like Maven or Ant?

Upvotes: 2

Related Questions