I currently have ClasspathSuite set up to run all of my JUnit tests. I'm working on trying to get the ClasspathSuite class to run from the command line. When I am in the bin directory and run this command:
java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore MySuite.class
I get:
JUnit version 4.10
Could not find class: MySuite.class
Time: 0.002
OK (0 tests)
I also tried running the same command with the absolute path to the file, resulting in the same error message. What am I doing wrong?
Just take off the .class part. Java knows to look in that file when you specify the class name.
java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore MySuite
Related
I have a project done in Java and we cannot use the IDE to compile it and run it, we are only allowed to use the command line. This project uses JSON. I have managed to successfully compiled and run it as follows:
Compile: javac -cp ./lib/java-json.jar ./src/project/*.java
Run: java -cp ./bin:./lib/java-json.jar project.Main
Now my next step is to run a JUnit test in the command line. To compile I tried:
javac [source files] -cp "path-to-JUnit-jar-files" path-to-JUnit-class
which looks like this:
javac ./src/project/.java -cp "./lib/JUnit/.jar" ./src/testing/AllTests.java
This is the closest I have gotten to successfully compiling the unit test class (I think) because it gave me only a few errors in comparison to other commands I have tried. The errors it gave me are that it needs the classpath to the JSON jar file, but I don't know how to tell the command line to do that.
Hello there are tests written on Java + cucumber
The structure is as follows:
https://i.imgur.com/moLVY6L.png
The main question is how to run this tests not from the IDE, say from the console or even wrap it all in jar file
The problems encountered are that you need the main class to create a jar,
It seems as there is a certain java cucumber.api.cli.Main - but how to use it I do not understand. Either way, there's probably a way to run this just from the command line. Please tell us how to do it?
You can download Maven with following terminal script :
$brew install maven
After brew installation, you need to go to the project directory which includes pom.xml file in terminal :
$cd /path/of/your/project
And finally you can run following command to run your tests :
$mvn clean test
You can try the below on command prompt.
java -cp "E:\Workspace\CucumberProj\Jars*;E:\Workspace\CucumberProj\bin" cucumber.api.cli.Main --glue stepDefination E:\Workspace\CucumberProj\Feature\Login_Test.feature
I've been developing a test suite for a provided "solution.jar" file in Eclipse for an assignment. I have a test suite which I can run in eclipse no problem, but the assignment requires that I run it from the command line, but I've no idea how to do this.
I've tried:
java -cp .;/usr/share/java/junit.jar org.junit.runner.JUnitCore AllTests
but it just said Error: could not load main class org.junit.runner.JUnitCore
Could someone help me out?
you can use maven build and then from command prompt fire this command
mvn test
It will run test case associated with your project.
I have command
sudo /opt/jdk1.7.0_79/bin/java -cp "/opt/workproject/lib/junit-4.10.jar" org.junit.runner.JUnitCore test
When I try to run I get:
JUnit version 4.10
Could not find class: test
If I try to run
sudo /opt/jdk1.7.0_79/bin/java -cp "/opt/workproject/lib/junit-4.10.jar,/opt/workproject/test-java/test.class" org.junit.runner.JUnitCore test
I have :
Could not find or load main class org.junit.runner.JUnitCore
I have all permissions rwx all groups I had execute chmode 777 on folder with libs and Test.class as well
Why I do have this problem, please help
standard way to run tests is either
running them in your IDE (eclipse/intelliJ)
running them with mvn clean test
I'd recommend that you should try one of these solutions first. They are much friendlier to developer than maintenance of tons of scripts for each test.
I've got the following structure
lib/junit-4.10.jar
tests/Tester.java
tests/Tester.class
build/jar/jar_file.jar
(Tester belongs to package tests)
I can compile tests using
javac -cp build/jar/jar_file.jar:lib/junit-4.10.jar tests/*.java
However I can't seem to run tests:
java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester
or
java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore Tester
And I get the following output:
JUnit version 4.10
Could not find class: tests.Tester
Time: 0.001
OK (0 tests)
How do I resolve this Could not find class problem? I think it may be classpath related.
Assuming this is Linux/Mac (not Windows) and your path separator is correct (:), since your test class files exist in package subdirectories under the current working directory (.)
You need to add "." to your class path, for example:
java -cp .:build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester
The classpath should be semi colon separated (on Windows - not sure what you are using.)
java -cp build/jar/jar_file.jar;lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester
Also with this command line you will need to run it in your project root