【问题标题】:JBehave parametrized alias ambiguityJBehave参数化别名歧义
【发布时间】:2015-03-13 20:33:18
【问题描述】:

使用 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

并将 $symbol 和 $threshold 替换为表中的示例。有没有 StoryTransformer 可以做到这一点?

【问题讨论】:

    标签: java testing jbehave


    【解决方案1】:

    这对我有用

    
      @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
    

    【讨论】:

      【解决方案2】:

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

      解决办法是这样改变配置:

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

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

      【讨论】:

        猜你喜欢
        • 2014-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多