黄瓜功能文件未从 Maven 执行
Cucumber feature file not executing from Maven
我正在尝试使用 maven 命令 mvn clean install
执行我的 cucumber
feature
文件,但它没有选择我的测试 class。我可以使用我的 IDE IntelliJ 运行 功能文件,但不能从命令行工作。请找到我的代码和 maven 依赖项。
我在这里遗漏了什么,为什么 mvn clean install 不选择 RunTest
并从这里 MyStepdefs
.
执行步骤定义
非常感谢任何帮助,过去两天我一直在苦苦挣扎 - 不确定我在这里做错了什么。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<configurationParameters>
cucumber.plugin=pretty,html:target/cucumber.html
cucumber.publish.quiet=true
cucumber.publish.enabled=false
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
test.feature
Feature: To retrieve the customer with customer details
Scenario: retrieve the customer with customer id
Given the customer saved with customer name "john" and customer id 100
When the client calls GET "/customer/{customerId}" with customer id as 100
RunTest.java
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class RunTest {
}
MyStepdefs.java
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
public class MyStepdefs {
@Given("the customer saved with customer name {string} and customer id {int}")
public void the_customer_saved_with_customer_name_and_customer_id(String string, Integer int1) {
System.out.println("Entering into given");
}
@When("the client calls GET {string} with customer id as {int}")
public void the_client_calls_get_with_customer_id_as(String string, Integer int1) {
System.out.println("Entering into when");
}
}
CucumberSpringConfig.java
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@CucumberContextConfiguration
@SpringBootTest(classes = DemoApplication.class)
public class CucumberSpringConfig {
}
这是我的文件夹结构:
Folder Structure
https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#use-the-cucumber-annotation
Cucumber will scan the package of a class annotated with @Cucumber
for feature files.
To use this feature, add the @Cucumber
annotation to the test runner. Doing so will make Cucumber run the feature files in the package containing the test runner.
因此,因为您注释的 class 在 com.example.demo
包中,所以将功能放在 src/test/resources/com/example/demo
中。
我正在尝试使用 maven 命令 mvn clean install
执行我的 cucumber
feature
文件,但它没有选择我的测试 class。我可以使用我的 IDE IntelliJ 运行 功能文件,但不能从命令行工作。请找到我的代码和 maven 依赖项。
我在这里遗漏了什么,为什么 mvn clean install 不选择 RunTest
并从这里 MyStepdefs
.
非常感谢任何帮助,过去两天我一直在苦苦挣扎 - 不确定我在这里做错了什么。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>6.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<properties>
<configurationParameters>
cucumber.plugin=pretty,html:target/cucumber.html
cucumber.publish.quiet=true
cucumber.publish.enabled=false
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
test.feature
Feature: To retrieve the customer with customer details
Scenario: retrieve the customer with customer id
Given the customer saved with customer name "john" and customer id 100
When the client calls GET "/customer/{customerId}" with customer id as 100
RunTest.java
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class RunTest {
}
MyStepdefs.java
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
public class MyStepdefs {
@Given("the customer saved with customer name {string} and customer id {int}")
public void the_customer_saved_with_customer_name_and_customer_id(String string, Integer int1) {
System.out.println("Entering into given");
}
@When("the client calls GET {string} with customer id as {int}")
public void the_client_calls_get_with_customer_id_as(String string, Integer int1) {
System.out.println("Entering into when");
}
}
CucumberSpringConfig.java
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@CucumberContextConfiguration
@SpringBootTest(classes = DemoApplication.class)
public class CucumberSpringConfig {
}
这是我的文件夹结构: Folder Structure
https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#use-the-cucumber-annotation
Cucumber will scan the package of a class annotated with
@Cucumber
for feature files. To use this feature, add the@Cucumber
annotation to the test runner. Doing so will make Cucumber run the feature files in the package containing the test runner.
因此,因为您注释的 class 在 com.example.demo
包中,所以将功能放在 src/test/resources/com/example/demo
中。