org.jbehave.core.steps.Steps $ DuplicateCandidateFound:那么结果将是$ expected

时间:2017-09-12 10:40:13

标签: java jbehave

我有以下jbehave故事文件:

ref.orderByChild('createdAt').startAt(Date.now()).on('child_added', ...

现在我想测试我的程序中的两个场景,所以我写了下面的代码:

Scenario: Scene1
Given the number of <input>
When the result is estimated
Then the result will be <expected>

Examples:
|input|expected|
|1|1|
|2|1, 2|
|3|1, 2, 3|
|4|1, 2, 3, 4|

Scenario: Scene2
Given the number of <input>
When the result is estimated
And the result is sorted in descending order
Then the result will be <expected>

Examples:
|input|expected|
|1|1|
|2|2, 1|
|3|3, 2, 1|
|4|4, 3, 2, 1|

当我运行测试用例时,我收到以下错误消息:

  

org.jbehave.core.steps.Steps $ DuplicateCandidateFound:那么结果   将是预期的

测试这两种情况的正确方法是什么,我在Java代码中需要做哪些更改。我不想改变我的故事档案。

这是我的JBehave配置文件:

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

public class EstimatorSteps {
    private Estimator estimator;

    @Given("the number of $input")
    public void given(int input) {
        estimator = new Estimator(input);
    }

    @When("the result is estimated")
    public void when1() {
        estimator.estimate(estimator.getInput());
    }

    @Then("the result will be $expected)
    public void then1(List<Integer> result) {
        assertEquals(estimator.getResult(), result);
    }

    @When("the result is sorted in descending order")
    public void when2() {
        estimator.descending(estimator.getResult());
    }

    @Then("the result will be $expected)
    public void then1(List<Integer> result) {
        assertEquals(estimator.getResult(), result);
    }
}

1 个答案:

答案 0 :(得分:2)

EstimatorSteps类中有两个相同的@Then步骤:

@Then("the result will be $expected)
public void then1(List<Integer> result) {
    assertEquals(estimator.getResult(), result);
}

....

@Then("the result will be $expected)
public void then1(List<Integer> result) {
    assertEquals(estimator.getResult(), result);
}

和JBehave抱怨:

DuplicateCandidateFound: THEN the result will be $expected

删除其中一种方法,不会出现错误。

BTW我想知道这个类是如何编译的,因为Java不应该允许两个具有完全相同签名的重载方法。