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.
这篇关于黄瓜测试没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:黄瓜测试没有运行


- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 转换 ldap 日期 2022-01-01