【问题标题】:Cucumber is not generating the code when executedCucumber 执行时不生成代码
【发布时间】:2020-05-08 22:02:15
【问题描述】:

我开始学习 Cucumber(行为驱动测试框架),并根据某些视频和一些阅读资料,我了解到 Cucumber 将自动为功能文件中定义的步骤定义生成骨架代码。但是,我没有看到任何正在执行的测试或正在生成的任何代码。我的项目设置如下

Project
  ----src/main/java/testrunner/MyTestRunner.java
  ----src/main/resources/feature/dailyroutine.feature

功能文件如下所示

Feature: Test Facebook smoke Scenario 
Scenario: Test with valid credentails
Given: Open firefox and start application
When: when I enter with valid username and password
Then: I should be able to login into Facebook Homepage

TestRunner如下

package testrunner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class) 
@CucumberOptions(features ={"src/main/resources/feature/dailyroutine.feature"},
             dryRun=true,
             strict=true,
             monochrome=true)
 public class MyTestRunner {

 }

当我将 TestRunner 作为 JUnit 运行时,我得到了 0 场景 0 步 0m0.000s

我做错了什么

【问题讨论】:

  • 你的黄瓜选项在你的路径中有空间?
  • 另外,您使用的关键字错误。 GIVEN:用于传递参数,(您可以输入“browserName”、“UserName”、“Password”WHEN:事件触发 THEN:断言
  • 我更改了 cucumberOptions。粘贴到stackoverflow时,额外的空间是一个错字。无论如何,我已经删除了额外的空间。你是说 Gherkin 关键字没有正确使用,因为没有生成骨架。
  • 我认为我的问题在于 GIVEN、WHEN 和 THEN 之后的冒号,删除它们后它工作正常。
  • 是的没错!,我也错过了哈哈,顺便看看我的回答,我可以建议另一种场景格式。

标签: cucumber


【解决方案1】:

我想提出一个替代的特征文件场景步骤

Feature Test Facebook smoke Scenario 
Scenario Success login with valid credentails
Given Using the browser "firefox"
And Username is "myUsername" with Password "myPassword"
When Submit login request
Then Successfully logged in to Facebook

【讨论】:

    【解决方案2】:

    问题可能在于功能文件的措辞方式,即 Given、When 和 Then 的额外冒号。

    我还对功能文件的编写方式进行了更改,以便更好地告知读者测试试图实现的目标 - 作为行为驱动开发(及其框架)的第一件事重点是开发团队和业务之间的沟通。

    Feature: Logging into Facebook...
    
      Scenario: with valid credentials
        Given I navigate to "Facebook"
        When I log in with my valid login details
        Then I should be able to see my newsfeed
    

    可能还有其他问题,但就目前而言,冒号是我最关心的问题

    编辑

    我应该阅读 cmets 部分,因为这个问题在这个答案前 2 天就解决了

    【讨论】:

      【解决方案3】:

      删除功能文件中关键字(Given、When 等)后面的冒号(:)。

      【讨论】:

      • 在数据表之前的步骤 def 之后放置冒号是一种不好的做法吗? ex -> 然后通知应该显示如下:(dataTable)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 2018-11-27
      相关资源
      最近更新 更多