简体   繁体   English

org.jbehave.core.steps.Steps $ DuplicateCandidateFound:然后结果将是$ expected

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

I have below jbehave story file: 我下面有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|

Now I wanted to test both the scenarios in my program, so I have written below code: 现在,我想测试程序中的两种情况,因此我编写了以下代码:

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

When I run the test case, I get below error message: 当我运行测试用例时,出现以下错误消息:

org.jbehave.core.steps.Steps$DuplicateCandidateFound: THEN the result will be $expected org.jbehave.core.steps.Steps $ DuplicateCandidateFound:然后结果将是$ expected

What is the right way to test both the cases, what changes I have to do in my Java code. 测试这两种情况的正确方法是什么,我必须在Java代码中进行哪些更改。 I do not want to change my story file. 我不想更改我的故事文件。

Here is my JBehave configuration file: 这是我的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(""));
    }
}

There are two identical @Then steps in EstimatorSteps class: 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);
}

and JBehave complains: JBehave抱怨:

DuplicateCandidateFound: THEN the result will be $expected

Remove one of these method and the error will not appear. 删除这些方法之一,将不会出现错误。

BTW I wonder how did this class compile at all, since Java shouldn't allow for two overloaded methods with exactly the same signature. 顺便说一句,我想知道该类是如何编译的,因为Java不应允许两个重载的方法具有完全相同的签名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 避免在Jbehave步骤中使用switch语句 - Avoid switch statement in Jbehave steps 来自相关项目的JBehave重用步骤 - JBehave reuse steps from dependent projects JBe如何在步骤之间保持对象状态 - JBehave how to persist objects state between steps 从Java内部动态调用JBehave步骤 - Dynamic calling of JBehave steps from inside Java 将步骤和预期结果从开发环境转移到 TestRail - Transfer of steps and expected result from the development environment to the TestRail JBehave RunningStoriesFailed 异常; org.jbehave.core.embedder.Embedder$RunningStoriesFailed - JBehave RunningStoriesFailed exception ; org.jbehave.core.embedder.Embedder$RunningStoriesFailed Serenity BDD:在本地故事中依赖使用JBehave步骤 - Serenity BDD: Use JBehave steps in dependency for local stories 如何使有状态的JBehave步骤对多线程执行安全 - How to make stateful JBehave steps safe for multithreaded execution 通过捕获失败步骤的失败原因,继续执行Serenity Jbehave BDD中的后续步骤 - Continue Execution of next steps in Serenity Jbehave BDD by capturing failure reason for the failed steps 在eclipse中运行jbehave测试时的org.jbehave.core.io.storyresourcenotfound异常 - org.jbehave.core.io.storyresourcenotfound exception when running jbehave test in eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM