黄瓜进程/子进程调用

时间:2016-10-04 08:19:04

标签: java cucumber cucumber-jvm

我使用的是Cucumber-JVM。

我有一个进程和一个子进程。该进程调用子进程然后继续。

理想情况下,我需要以下方案:

Scenario: Process
 Given I start a process
 When I have completed the sub process
 And then I complete task A
 And then I complete task B
 Then the process is finished

Scenario: SubProcess
 Given I start a subprocess
 When I complete task C
 And then I complete task D
 Then the process is finished

我想知道什么是编码的最佳方法"当我完成子流程"

我已经阅读了一些关于从步骤定义中调用步骤的内容,但是在cucumber-jvm中不支持它们。这是唯一可用的选项还是其他选项?理想情况下,我会调用整个场景而不是单个步骤。

2 个答案:

答案 0 :(得分:0)

可能这不是你想要的答案......但是我在这些情况下做的是创造一个新的'步骤分组场景中涉及的所有步骤。我知道这不是一个优雅的解决方案,但我认为cucumber-jvm中没有其他选项。见closed issue

您的用例示例:

@When("^I have completed the sub process$")
public void I_have_completed_the_sub_process() throws Throwable {
 I_complete_task_C();
 I_complete_task_D();
 the_process_is_finished();
}

然后,您可以在given方案背景条件中使用此新步骤。这样的事情:

Background:
 Given I have completed the sub process

Scenario: Process
 Given I start a process     
 And then I complete task A
 And then I complete task B
 Then the process is finished

我会等待其他答案,希望有更好的选择。 希望它有所帮助。

答案 1 :(得分:0)

如果我正确理解了这个问题,假设您只想为Process运行SubProcess一次,那么您要查找的是一个表(或Scenario Outline)。

 Scenario: Process

 Given I start a process
 When I have completed the sub process "<x>" "<y>" "<z>"
| x |   y | z|
 And then I complete task A
 And then I complete task B
 Then the process is finished

Scenario Outline: Process
 Given I start a process
 When I have completed the sub process "<x>" "<y>" "<z>"
 And then I complete task A
 And then I complete task B
 Then the process is finished
| x |   y | z|

Scenario Outline: SubProcess
 Given I start a subprocess "<x>"
 When I complete task C "<y>"
 And then I complete task D "<z>"
 Then the process is finished
 Examples:
 | x  |  y   |  z   |

@When("^I have completed the sub process (.*) (.*) (.*)$")
public void I_have_completed_the_sub_process(String x, String y, String z) throws Throwable {
  I_start_a_subprocess(x);
  .....
  <your code>;
}

你也可以让黄瓜将列中的所有值作为列表返回

但如果这涉及大量配置数据,您可能想从数据源(如yaml文件)读取配置并将密钥传递给该步骤。

yaml文件:

:configuration:
    :x: "val1"
    :y: "val2"
    :z: "val3"

你的步骤只需要一个输入

When I have completed the sub process "<configuration>"

步骤定义解析hashmap并根据需要将值传递给steps方法。

或者您可以将值作为表格,创建类配置,步骤定义将列表值作为输入: https://thomassundberg.wordpress.com/2014/06/30/cucumber-data-tables/

public class Config{
private String x,
private String y,
Private String z }

public void step_definition_function(<List>Config config){}
相关问题