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.
Related
I downloaded the latest Cucumber Java version - 4.7.2, and am ale to run the cucumber test from IDE Intellij, everything is fine in IDE. However, if run from command line then it gives me error "io.cucumber.junit.UndefinedThrowable:"
Run test runner "RunCucumberTest" in IDE: OK
Cucumber-jvm Approach:
java -cp "lib/cucumber-4.7.2/*" io.cucumber.core.cli.Main --glue au.com.demo.quality.stepdefinitions --plugin pretty --name "^demo test$" src/test/resources/features/DemoTest.feature
result: step undefined as above
JUnit Approach:
java -cp "../lib/cucumber-4.7.2/*;../out/production/demo" org.junit.runner.JUnitCore au.com.demo.quality.runners.RunCucumberTest
result: step undefined as above
Project structure:
Quality
-lib
-out
--Production
---demo
......
-bdd
--src
---test
----java
----resources
More details as shown in the screenshot below.
the cucumber structure
I have searched in stackoverflow and google searched as well, no answer found. Useful refereces here but they are not my answer. Thanks.
https://github.com/cucumber/cucumber-jvm/issues/1127#issuecomment-303486249
Cucumber cannot find StepDefinitions while running the code but manually using the option "Find Step" can find step definition
How to run cucumber file from command line
https://www.toolsqa.com/cucumber/cucumber-options/
I figured it out. The step definition class is not able to extend another class, otherwise the step definitions wont be found.
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 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
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