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.
Related
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
Trying to do some automated test. I have used below commands to execute the junit file (RunnerTest.java) in command line, getting an error as "could not find class"
Command line commands:
C:\Users\username\workspace\MavenCucumberPrototype\src\test\java\com\cucumber\MavenCucumberPrototype>javac -cp "C:/cjars/*" MavenCucumberPrototype/*.java
C:\Users\username\workspace\MavenCucumberPrototype>java -classpath C:/cjars/junit-4.12.jar org.junit.runner.JUnitCore src.test.java.com.cucumber.MavenCucumberPro
totype.RunnerTest
Maven Project structure
MavenCucumberPrototype
-/src/main/java
-com.cucumber.MavenCucumberPrototype
-/src/test/java
-com.cucumber.MavenCucumberPrototype
-postconn.java
-RunnerTest.java
-Steps.java
-/src/test/resource
-myfeature.feature
When I run Maven projects from a command line, I usually do
mvn clean install
or whatever lifecycle phase I want to execute. In your case, it might be sufficient to do
mvn test
The only imprtant thing to notice is that you must execute the command in the same directory as the pom.xml resides.
The error you recieve is nost likely due to a classpath that doesn't contain what you expected.
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 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