Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 小黄瓜/黄瓜-我们可以分组吗;什么时候;类似“的声明”;给定;s在“中”;“背景”吗;?_Java_Cucumber_Gherkin - Fatal编程技术网

Java 小黄瓜/黄瓜-我们可以分组吗;什么时候;类似“的声明”;给定;s在“中”;“背景”吗;?

Java 小黄瓜/黄瓜-我们可以分组吗;什么时候;类似“的声明”;给定;s在“中”;“背景”吗;?,java,cucumber,gherkin,Java,Cucumber,Gherkin,我正在用小黄瓜/黄瓜迈出第一步 我一直在通过官方文档阅读语法以及何时/如何适当地使用每个标记,但是我想知道是否有一种适当的方式将某些在“何时”阶段反复使用的语句分组,类似于将“背景”部分中的“给定”语句分组 例如: Feature: Wanting to reduce code duplications Background: Given I have done some set up And I have done some more set up @Scenario_1 S

我正在用小黄瓜/黄瓜迈出第一步

我一直在通过官方文档阅读语法以及何时/如何适当地使用每个标记,但是我想知道是否有一种适当的方式将某些在“何时”阶段反复使用的语句分组,类似于将“背景”部分中的“给定”语句分组

例如:

Feature: Wanting to reduce code duplications
Background:
    Given I have done some set up
    And I have done some more set up

@Scenario_1
Scenario: An example scenario
    # Some Givens defined in Background
    Given a unique step is taken
    # When
    When I perform some action that will be repeated
        And I perform another action that will be repeated
        And I perform a non-repeated task
    # Then
    Then something will be expected at the end

@Scenario_2
Scenario: An second example scenario
    # Some Givens defined in Background
    Given a different unique step is taken
    # When
    When I perform some action that will be repeated
        And I perform another action that will be repeated
        And I perform a different non-repeated task
    # Then
    Then something different will be expected at the end
Given I go to a website
When when I click on username and typ 'User1'
And when I click on password and typ 'welcome123'
And when I click on the login button
Then the dashboard is shown
And I see that there is a proper header
是否有任何方式可以将“When”语句抽象或分组:

When I perform some action that will be repeated
And I perform another action that will be repeated

首先,请记住,小黄瓜应该是BDD,意思是行为驱动的开发。您陈述步骤的方式不是行为,而是行动<代码>当我执行一些将重复的操作时不会描述系统或用户的任何行为

对于重复任务,生成一个描述行为的
When
,然后在Java代码中定义所需的所有重复步骤

例如:

Feature: Wanting to reduce code duplications
Background:
    Given I have done some set up
    And I have done some more set up

@Scenario_1
Scenario: An example scenario
    # Some Givens defined in Background
    Given a unique step is taken
    # When
    When I perform some action that will be repeated
        And I perform another action that will be repeated
        And I perform a non-repeated task
    # Then
    Then something will be expected at the end

@Scenario_2
Scenario: An second example scenario
    # Some Givens defined in Background
    Given a different unique step is taken
    # When
    When I perform some action that will be repeated
        And I perform another action that will be repeated
        And I perform a different non-repeated task
    # Then
    Then something different will be expected at the end
Given I go to a website
When when I click on username and typ 'User1'
And when I click on password and typ 'welcome123'
And when I click on the login button
Then the dashboard is shown
And I see that there is a proper header
基本上,在这种情况下,您正在用小黄瓜描述一个物理测试用例

您真正想要实现的是:

Given I navigate to a website
When I login
Then the dashboard is shown by system
当然,你可以详细说明这些步骤,比如:

Given I navigate to website 'http://www.google.com/' in browser 'Chrome'
When I login as user 'User1'
Then the dashboard is shown by system
通过这种方式,您可以立即知道测试在做什么,使用的主要数据是什么,并且可以快速查看它是否满足要求


因此,在您的情况下,尝试减少小黄瓜中的步骤描述,您的重复项将自动减少。

我明白了。尝试将在每个场景中重复的一组步骤缩减为一个更大的步骤是有用的。