2017-09-12 8 views
1

ことが期待されます私は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 $ DuplicateCandi検出日:THEN結果 ドル

を期待されます私は私の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("")); 
    } 
} 

答えて

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 

を削除するこれらの方法とエラーのいずれかが表示されません。

私はこのクラスがまったくどのようにコンパイルされたのだろうと思っています。なぜなら、Javaはまったく同じシグネチャを持つ2つのオーバーロードされたメソッドを許可すべきではないからです。

+0

両方の方法にも終了引用符がありません。私はこれがどのようにしてコンパイルされているかについても興味があります。 –