JBehave 参数化别名歧义

JBehave parametrized alias ambiguity

使用 jBehave,我想对参数化和非参数化步骤使用一种方法。 文档 (http://jbehave.org/reference/stable/parametrised-scenarios.html) 说我可以使用这样的别名:

@Given("a stock of symbol $symbol and a threshold of $threshold") // standalone
@Alias("a stock of <symbol> and a <threshold>") // examples table
public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
    // ...
}

但它不允许我使用完全相同的句子。我想做的是:

@Given("a stock of symbol $symbol and a threshold of $threshold") // standalone
@Alias("a stock of symbol <symbol> and a threshold of <threshold>") // examples table
public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
    // ...
}

但是弹出警告:"Ambiguous step".

我该怎么做?

最好只写:

@Given("a stock of symbol $symbol and a threshold of $threshold") // standalone

并用table中的例子替换$symbol和$threshold。是否有可以实现此目的的 StoryTransformer?

这对我有用


  @Given("a stock of symbol $symbol and a threshold of $threshold")
  public void aStock(@Named("symbol") String symbol, @Named("threshold") double threshold) {
    System.out.printf("Output From Method: symbol: %s, threshold: %s\n", symbol, threshold);
  }

故事文件:


Trader Test


Scenario: test single method
Given a stock of symbol blah and a threshold of 6

Scenario: test again with examples table
Given a stock of symbol <symbol> and a threshold of <threshold>

Examples: 
|symbol|threshold|
| abc  |  2      |
| 123  |  3      |
| asdf |  4      |
| jbe  |  5      |
| have |  6      |

输出


Scenario: test single method
Output From Method: symbol: blah, threshold: 6.0
Given a stock of symbol blah and a threshold of 6

Scenario: test again with examples table
Examples:
Given a stock of symbol  and a threshold of 

|symbol|threshold|
|abc|2|
|123|3|
|asdf|4|
|jbe|5|
|have|6|

Example: {symbol=abc, threshold=2}
Output From Method: symbol: abc, threshold: 2.0
Given a stock of symbol abc and a threshold of 2

Example: {symbol=123, threshold=3}
Output From Method: symbol: 123, threshold: 3.0
Given a stock of symbol 123 and a threshold of 3

Example: {symbol=asdf, threshold=4}
Output From Method: symbol: asdf, threshold: 4.0
Given a stock of symbol asdf and a threshold of 4

Example: {symbol=jbe, threshold=5}
Output From Method: symbol: jbe, threshold: 5.0
Given a stock of symbol jbe and a threshold of 5

Example: {symbol=have, threshold=6}
Output From Method: symbol: have, threshold: 6.0
Given a stock of symbol have and a threshold of 6

Mauro Talevi 在 jBehave 邮件列表上回复了我:http://markmail.org/thread/ef3pfkjoiuuxvic6#query:+page:1+mid:33appvwdkfboyshx+state:results

解决方案是像这样更改配置:

new MostUsefulConfiguration()
    .useParameterControls(new ParameterControls().useDelimiterNamedParameters(true));

这可能是 bbark 在其回答中使用的配置。