Java 如何从命令行运行黄瓜文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30586937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:51:23  来源:igfitidea点击:

How to run cucumber file from command line

javacucumber-jvmcucumber-junit

提问by Durgesh

I have cucumber feature file located at below location on my local:

我在本地的以下位置有黄瓜特征文件:

C:\ProjectWork\Workspace\Cucumber\DIT_Cucumber\src\cucumber\featureOne.feature

and Junit jar at below location:

和 Junit jar 在以下位置:

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

Below are the commands which I used: Command 1:

以下是我使用的命令: 命令 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

Command 2:

命令 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.

你能帮我从命令行运行这个功能文件吗?提前致谢。

回答by Sébastien Le Callonnec

JUnit Approach

JUnit 方法

If using JUnit, you can run the test the same way you would run a JUnit test on the command line:

如果使用 JUnit,您可以像在命令行上运行 JUnit 测试一样运行测试:

java -cp <classpath> org.junit.runner.JUnitCore com.example.test.RunCukesTest

where RunCukesTestis the unit test that sets all the cucumber options, e.g.:

RunCukesTest设置所有黄瓜选项的单元测试在哪里,例如:

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 Approach

Cucumber-jvm 方法

You can also use cucumber-jvm on the command line:

你也可以在命令行上使用cucumber-jvm:

java -cp <classpath> cucumber.api.cli.Main \
   --glue com.example.test \
   --plugin pretty path/to/features

Maven

马文

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:

前两种情况的挑战是构建类路径并确保正确加载所有依赖项,包括您自己的类和功能文件。一个更简单的解决方案是使用例如Maven 来定义所有的 deps;运行测试就像这样简单:

mvn verify

回答by Sathya Kanuri

Cucumber with Java:

黄瓜与Java:

Run Feature: java -cp "jars/*" cucumber.api.cli.Main -p pretty features

运行特点: java -cp "jars/*" cucumber.api.cli.Main -p pretty features

compile Step Definition file: javac -cp "jars/*" step_definition/StepDef.java

编译步骤定义文件: javac -cp "jars/*" step_definition/StepDef.java

Run Scenario: java -cp "jars/*;." cucumber.api.cli.Main -p pretty -g step_definition features

运行场景: java -cp "jars/*;." cucumber.api.cli.Main -p pretty -g step_definition features