当 运行 测试 运行ner 时得到输出 0 Scenarios
Got the output as 0 Scenarios when run the test runner
我正在尝试 运行 作为学习黄瓜的一部分进行一些测试。但我得到的结果是 0 个场景。在这里我添加我写的代码:
Login.feature 与-
Feature: Application Login S
Scenario : Home page default login
Given User is on Net banking landing page
When user login into the application with username and password
Then Home page is populated
And Cards are displayed
步骤定义:
package stepDefinitions;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.And;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class StepDefinition {
@Given("^User is on Net banking landing page$")
public void user_is_on_net_banking_landing_page() throws Throwable {
System.out.println("User on landing page");
}
@When("^user login into the application with username and password$")
public void user_login_into_the_application_with_username_and_password() throws Throwable {
System.out.println("Login successfully");
}
@Then("^Home page is populated$")
public void home_page_is_populated() throws Throwable {
System.out.println("User on Home page");
}
@And("^Cards are displayed$")
public void cards_are_displayed() throws Throwable {
System.out.println("Displaying cards");
}
}
测试运行程序 -
package com.edstem.CucumberOptions;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features",
glue = {"stepDefinitions"})
public class TestRunner {
}
pom.xml -
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>cucumber-learning</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.0.11</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.3</version>
</dependency>
</dependencies>
</project>
输出:
0 场景
0 步
0m0.000s
进程已完成,退出代码为 0features = "src/test/java/features",
你能给我一个解决方案吗,因为我找不到解决它的方法。
假设您的功能文件正确放置在 src/test/java/features
中,问题是您的胶水没有正确设置到步骤定义或类路径缺少配置文件路径。
检查两者,如果仍然不起作用,请post您的运行配置和项目结构。
1) 您不需要使用@RunWith 注释您的步骤定义class。跑步者就足够了
2) 特征应该放在 src/test/resources/features 而不是 src/test/java
3) 您使用的是非常旧版本的黄瓜。尝试切换到最新版本
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
Scenario
和 :
之间的 space 是问题
替换此
Scenario : Home page default login
有
Scenario: Home page default login
我正在尝试 运行 作为学习黄瓜的一部分进行一些测试。但我得到的结果是 0 个场景。在这里我添加我写的代码:
Login.feature 与-
Feature: Application Login S
Scenario : Home page default login
Given User is on Net banking landing page
When user login into the application with username and password
Then Home page is populated
And Cards are displayed
步骤定义:
package stepDefinitions;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.And;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
public class StepDefinition {
@Given("^User is on Net banking landing page$")
public void user_is_on_net_banking_landing_page() throws Throwable {
System.out.println("User on landing page");
}
@When("^user login into the application with username and password$")
public void user_login_into_the_application_with_username_and_password() throws Throwable {
System.out.println("Login successfully");
}
@Then("^Home page is populated$")
public void home_page_is_populated() throws Throwable {
System.out.println("User on Home page");
}
@And("^Cards are displayed$")
public void cards_are_displayed() throws Throwable {
System.out.println("Displaying cards");
}
}
测试运行程序 -
package com.edstem.CucumberOptions;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features",
glue = {"stepDefinitions"})
public class TestRunner {
}
pom.xml -
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>cucumber-learning</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.0.11</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.3</version>
</dependency>
</dependencies>
</project>
输出: 0 场景 0 步 0m0.000s
进程已完成,退出代码为 0features = "src/test/java/features",
你能给我一个解决方案吗,因为我找不到解决它的方法。
假设您的功能文件正确放置在 src/test/java/features
中,问题是您的胶水没有正确设置到步骤定义或类路径缺少配置文件路径。
检查两者,如果仍然不起作用,请post您的运行配置和项目结构。
1) 您不需要使用@RunWith 注释您的步骤定义class。跑步者就足够了
2) 特征应该放在 src/test/resources/features 而不是 src/test/java
3) 您使用的是非常旧版本的黄瓜。尝试切换到最新版本
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>5.7.0</version>
Scenario
和 :
之间的 space 是问题
替换此
Scenario : Home page default login
有
Scenario: Home page default login