Cucumber test not running(黄瓜测试没有运行)
问题描述
我正在开发我的第一个功能文件/selenium 项目.
I am working on my first feature file/selenium project.
我已经创建了一个特性文件和运行器类.
I have created a feature file and runner class.
package cucumberpkg2;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions
(features="Features")
public class Runner {
}
我有功能文件 test.feature
I have the feature file test.feature
Feature: Login screen
Scenario Outline: Successful login
Given User is on Login page
When User enters valid UserName and Password
And Clicks the login button
Then User landed on the home page
但每当我尝试将 TestRunner 类作为 JUnit 测试运行时,我都会收到错误消息:
But whenever I try to run the TestRunner class as a JUnit test, I get the error:
在所选项目中找不到测试类.
Test class not found in selected project.
推荐答案
这是您问题的解决方案:
Here is the solution to your Question:
- 根据 Cucumber 的当前文档,您可能需要更改关键字
Scenario Outline
到test.feature
文件中的Scenario
. - 虽然您提到了
TestRunner
类,但您的代码谈到了Runner
类被实现为public class Runner
,请确定哪个类文件是你执行为JUnit 测试
. - 对于以前的版本,您可能需要将
@CucumberOptions
更改为@Cucumber.Options
(最近的版本使用@CucumberOptions
) - 将以下两部分放在一行中作为
@Cucumber.Options(features="Features")
- 正如您将提到的
@Cucumber.Options(features="Features")
确保您的功能文件放置在项目目录中的Features
子目录中. 因此,您将在
Features
子目录中拥有test.feature
文件,其中包含以下代码:
- As per the current documentation of Cucumber you may require to change the keyword
Scenario Outline
toScenario
intest.feature
file. - Though you mentioned about
TestRunner
class but your code speaks aboutRunner
class being implemented aspublic class Runner
, be sure which class file are you executing asJUnit test
. - You may require to change
@CucumberOptions
to@Cucumber.Options
for previous versions (recent versions work with@CucumberOptions
) - Put the following 2 parts in a single line as
@Cucumber.Options (features="Features")
- As you would be mentioning
@Cucumber.Options(features="Features")
ensure that your feature file is placed insideFeatures
sub-directory within the Project Directory. So you will be having,
test.feature
file withinFeatures
sub-directory with the following code:
Feature: Login screen
Scenario: Successful login
Given User is on Login page
When User enters valid UserName and Password
And Clicks the login button
Then User landed on the home page
您的 Runner
类将如下所示:
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features")
public class Runner {
}
最后,当您将 Runner
类作为 JUnit 测试执行时,您将在控制台上看到以下消息:
Finally when you will execute Runner
class as a JUnit test you will see the following message on your console:
You can implement missing steps with the snippets below:
@Given("^User is on Login page$")
public void User_is_on_Login_page() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@When("^User enters valid UserName and Password$")
public void User_enters_valid_UserName_and_Password() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@When("^Clicks the login button$")
public void Clicks_the_login_button() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
@Then("^User landed on the home page$")
public void User_landed_on_the_home_page() throws Throwable {
// Express the Regexp above with the code you wish you had
throw new PendingException();
}
通过对 Cucumber 实施 glue
选项,可以轻松处理这些警告.
These warnings can be taken care easily by implementing the glue
options to Cucumber.
如果这能回答您的问题,请告诉我.
Let me know if this Answers your Question.
这篇关于黄瓜测试没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:黄瓜测试没有运行
基础教程推荐
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01