黄瓜测试没有运行 [英] Cucumber test not running

查看:22
本文介绍了黄瓜测试没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发我的第一个功能文件/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:

  1. 根据 Cucumber 的当前文档,您可能需要更改关键字 Scenario Outlinetest.feature 文件中的 Scenario.
  2. 虽然您提到了 TestRunner 类,但您的代码谈到了 Runner 类被实现为 public class Runner,请确定哪个类文件是你执行为 JUnit 测试.
  3. 对于以前的版本,您可能需要将 @CucumberOptions 更改为 @Cucumber.Options(最近的版本使用 @CucumberOptions)
  4. 将以下两部分放在一行中作为 @Cucumber.Options(features="Features")
  5. 正如您将提到的 @Cucumber.Options(features="Features") 确保您的功能文件放置在项目目录中的 Features 子目录中.
  6. 因此,您将在 Features 子目录中拥有 test.feature 文件,其中包含以下代码:

  1. As per the current documentation of Cucumber you may require to change the keyword Scenario Outline to Scenario in test.feature file.
  2. Though you mentioned about TestRunner class but your code speaks about Runner class being implemented as public class Runner, be sure which class file are you executing as JUnit test.
  3. You may require to change @CucumberOptions to @Cucumber.Options for previous versions (recent versions work with @CucumberOptions)
  4. Put the following 2 parts in a single line as @Cucumber.Options (features="Features")
  5. As you would be mentioning @Cucumber.Options(features="Features") ensure that your feature file is placed inside Features sub-directory within the Project Directory.
  6. So you will be having, test.feature file within Features 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.

    这篇关于黄瓜测试没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆