如何从命令行运行黄瓜文件 [英] How to run cucumber file from command line
问题描述
我的黄瓜功能文件位于我当地的下方位置:
I have cucumber feature file located at below location on my local:
C:\ProjectWork\Workspace\Cucumber\DIT_Cucumber\src\cucumber\featureOne.feature
和Junit jar位于以下位置:
and Junit jar at below location:
C:\DurgeshProjectWork\Workspace\JarFiles\junit-4.11.jar
当我尝试了以下几个命令从命令提示符执行功能文件时,但总是得到与
When I have tried several commands like below to execute the feature file from command prompt however all the time getting same error as
Could not fine class
以下是我使用的命令:
命令1:
Below are the commands which I used: Command 1:
C:\>java -cp C:\ProjectWork\Workspace\JarFiles\junit-4.11.jar org.junit.runner.JUnitCore C:\DurgeshProjectWork\Workspace\Cucumbe
r\DIT_Cucumber\bin\cucumber\featureOne.feature
Comman d 2:
Command 2:
C:\ProjectWork\Workspace\Cucumber\DIT_Cucumber\src\cucumber>java -cp C:\ProjectWork\Workspace\JarFiles\junit-4.11.jar org
.junit.runner.JUnitCore featureOne.feature
请帮我从命令行运行此功能文件。在此先感谢。
Could you please help me to run this feature file from command line. Thanks in advance.
推荐答案
JUnit方法
如果使用JUnit,您可以像在命令行上运行JUnit测试一样运行测试:
If using JUnit, you can run the test the same way you would run a JUnit test on the command line:
java -cp <classpath> org.junit.runner.JUnitCore com.example.test.RunCukesTest
其中 RunCukesTest
是设置所有黄瓜选项的单元测试,例如:
where RunCukesTest
is the unit test that sets all the cucumber options, e.g.:
package com.example.test;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = "json:target/report.json")
public class RunCukesTest {
}
Cucumber-jvm方法
您还可以在命令行中使用cucumber-jvm:
You can also use cucumber-jvm on the command line:
java -cp <classpath> cucumber.api.cli.Main \
--glue com.example.test \
--plugin pretty path/to/features
Maven
前两种情况的挑战是构建类路径和确保正确加载所有依赖项,包括您自己的类和功能文件。一个更简单的解决方案是使用例如 Maven to定义所有deps ;然后运行测试很简单:
The challenge in both previous cases is to build the classpath and make sure all the dependencies are properly loaded, including your own classes and the feature files. An easier solution would be to use for example Maven to define all the deps; running the tests is then as simple as:
mvn verify
这篇关于如何从命令行运行黄瓜文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!