簡體   English   中英

org.jbehave.core.steps.Steps $ DuplicateCandidateFound:然后結果將是$ expected

[英]org.jbehave.core.steps.Steps$DuplicateCandidateFound: THEN the result will be $expected

我下面有jbehave故事文件:

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|

現在,我想測試程序中的兩種情況,因此我編寫了以下代碼:

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);
    }
}

當我運行測試用例時,出現以下錯誤消息:

org.jbehave.core.steps.Steps $ DuplicateCandidateFound:然后結果將是$ expected

測試這兩種情況的正確方法是什么,我必須在Java代碼中進行哪些更改。 我不想更改我的故事文件。

這是我的JBehave配置文件:

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.io.CodeLocations;
import org.jbehave.core.io.LoadFromClasspath;
import org.jbehave.core.io.StoryFinder;
import org.jbehave.core.junit.JUnitStories;
import org.jbehave.core.reporters.StoryReporterBuilder;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;

import java.util.Arrays;
import java.util.List;

import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
import static org.jbehave.core.reporters.StoryReporterBuilder.Format.CONSOLE;

public class JBehaveStories extends JUnitStories {

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass()))
                .useStoryReporterBuilder(new StoryReporterBuilder()
                        .withCodeLocation(codeLocationFromClass(this.getClass())).withFormats(CONSOLE));
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration(), new EstimatorSteps());
    }

    @Override
    protected List<String> storyPaths() {
        return new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()),
                Arrays.asList("**/*.story"), Arrays.asList(""));
    }
}

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

刪除這些方法之一,將不會出現錯誤。

順便說一句,我想知道該類是如何編譯的,因為Java不應允許兩個重載的方法具有完全相同的簽名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM