简体   繁体   English

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

[英]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

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. 提前致谢。

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 RunCukesTest is the unit test that sets all the cucumber options, eg: 其中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 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 ; 一个更简单的解决方案是使用例如Maven来定义所有deps ; running the tests is then as simple as: 运行测试就像下面这样简单:

mvn verify

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 java -cp "jars/*;." cucumber.api.cli.Main -p pretty -g step_definition features

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM