Skip to main content



      Home
Home » Newcomers » Newcomers » How to run my JUnit tests that I built in Eclipse from command line(Junit Command line execution)
How to run my JUnit tests that I built in Eclipse from command line [message #1728189] Thu, 31 March 2016 14:32 Go to next message
Eclipse UserFriend
Hi,

I'm a newbie to JUnit. I have created some tests inside of eclipse and using "Run as" inside of eclipse to execute my tests.

I want to know how can I run these same tests from a command line?

Example, what are all the steps necessary?

I have set my environment variables (e.g. JAVA_HOME and JUNIT_HOME) and also added them to the classpath as well.

What else do I need to do, do I need to add the location of my bin project folder containing the .class files to the classpath or anywhere?

I tried to run the following commands:

1)
java -classpath C:\JUnit\junit-4.12.jar;C:\Users\tarik.abdallah\workspace\RentalManTests\bin\com\wynnesystems\rentalman\tests; org.junit.runner.JUnitCore OperationScreenTests

Got this error:
Exception in thread "main" java.lang.NoClassDefFoundError: OperationScreenTests (wrong name: com/wynnesystems/rentalman/tests/OperationScreenTests)

2)
c:\JUnit>java -classpath C:\JUnit\junit-4.12.jar org.junit.runner.JUnitCore OperationScreenTests

Got this error:
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [OperationScreenTests]
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)
at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: OperationScreenTests
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.junit.internal.Classes.getClass(Classes.java:16)
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
... 4 more

I tried many things but have not had any luck... This should really be easy to do -(


Re: How to run my JUnit tests that I built in Eclipse from command line [message #1728191 is a reply to message #1728189] Thu, 31 March 2016 14:45 Go to previous messageGo to next message
Eclipse UserFriend
This really isn't too much an Eclipse question, but here are some things
to think about.

1) If you're using Maven, you get this for free by typing "mvn compile
test" at the root of your project.

2) If you want to run them in Java (as it were and as you are describing
here), you will have to a) create a main() that invokes your tests and
b) a runnable JAR around that main(). This is a lot of mostly
unnecessary work and not really best industry practice.

Number (1) above is your best bet and you'll never regret learning and
beginning to use Maven whether in Eclipse, in another IDE or at the
command line.

Hope this helps.
Re: How to run my JUnit tests that I built in Eclipse from command line [message #1728299 is a reply to message #1728191] Fri, 01 April 2016 13:35 Go to previous messageGo to next message
Eclipse UserFriend
The first error message is giving you the answer: You must give the fully-qualified name of the class, such as com.wynnesystems.rentalman.tests.OperationScreenTests
Re: How to run my JUnit tests that I built in Eclipse from command line [message #1728300 is a reply to message #1728191] Fri, 01 April 2016 13:38 Go to previous messageGo to next message
Eclipse UserFriend
Russell Bateman wrote on Thu, 31 March 2016 18:45
This really isn't too much an Eclipse question, but here are some things
to think about.

1) If you're using Maven, you get this for free by typing "mvn compile
test" at the root of your project.

For the record, Gradle and Ant also provide similar convenience.


Quote:
2) If you want to run them in Java (as it were and as you are describing
here), you will have to a) create a main() that invokes your tests and
b) a runnable JAR around that main(). This is a lot of mostly
unnecessary work and not really best industry practice.

The JUnitCore class that Tarik is tryingto use is basically that.
Re: How to run my JUnit tests that I built in Eclipse from command line [message #1728492 is a reply to message #1728299] Mon, 04 April 2016 18:11 Go to previous message
Eclipse UserFriend
I tried using the fully qualified class name but still no luck, same error received.

[Updated on: Tue, 05 April 2016 13:50] by Moderator

Previous Topic:Newbie in bug fixing
Next Topic:Login Radius in Eclipse
Goto Forum:
  


Current Time: Tue Jul 08 20:59:00 EDT 2025

Powered by FUDForum. Page generated in 0.11475 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top