Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 18:32 Go to next message
Tarik Abdallah is currently offline Tarik AbdallahFriend
Messages: 3
Registered: March 2016
Junior Member
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 18:45 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

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 17:35 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
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 17:38 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
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 22:11 Go to previous message
Tarik Abdallah is currently offline Tarik AbdallahFriend
Messages: 3
Registered: March 2016
Junior Member
I tried using the fully qualified class name but still no luck, same error received.

[Updated on: Tue, 05 April 2016 17:50]

Report message to a moderator

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


Current Time: Sat Apr 27 01:06:17 GMT 2024

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

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

Back to the top