Jbehave有0个故事

时间:2017-02-08 19:56:21

标签: java bdd jbehave

我是java和jbehave的新手。我想用jbehave尝试BDD,但似乎做错了 - 测试运行但步骤没有执行。

POJO CLASS:

public class Addition {

    public int result;

    public void addValues(int a,int b){
        result=a+b;
    }

    public int getResult(){
        return result;
    }

}

STEPS CLASS:

public class AdditionStep {

    private Addition calc;

    @Given("open calc")
    public void openCalc(){
        calc=new Addition();
        System.out.println("Opened calc");
    }

    @When("i add $number1 to $number2")
    public void addition(@Named("number1")int a,@Named("number2")int b){
        calc.addValues(a, b);
    }

    @Then("outcome is $result")
        public void checkSum(@Named("result")int output){
        Assert.assertEquals(output, calc.getResult());
        System.out.println("Sum is : "+output);
    }
}

STORY RUNNER:

public class AdditionStory extends JUnitStories {

    @Override
    public Configuration configuration(){
        return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(this.getClass())).
            useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().
            withFormats(Format.CONSOLE,Format.TXT));
    }

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

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

故事文件:

Scenario: Add two valid numbers
Given open calc
When i add 1 to 1
Then outcome is 2`

POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>JbehaveCalculatorTest</groupId>
<artifactId>JbehaveCalculatorTest</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jbehave.core.version>4.1</jbehave.core.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.2.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-core</artifactId>
        <version>${jbehave.core.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>

</dependencies>


<build>
    <testResources>
        <testResource>
            <directory>src/test/java</directory>
            <includes>
                <include>**/*.story</include>
            </includes>
        </testResource>
    </testResources>
    <plugins>
    <plugin>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-maven-plugin</artifactId>
        <version>${jbehave.core.version}</version>
        <executions>
            <execution>
                <id>run-stories</id>
                <phase>test</phase>
                <configuration>
                    <!--<scope>test</scope>-->
                    <includes>
                        <include>**/stories/*.java</include>
                    </includes>
                </configuration>
                <goals>
                    <goal>run-stories-as-embeddables</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    </plugins>
</build>
</project>

我的故事档案放在src / test / java / Stories /...

输出:

Processing system properties {} Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeouts=300,threads=1,failOnStoryTimeout=false]

(BeforeStories)

(AfterStories)

Generating reports view to 'D:\KnowledgeCentre\Workspace\JbehaveCalculatorTest\target\jbehave' using formats '[stats, console, txt]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}' Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending) Disconnected from the target VM, address: '127.0.0.1:49908', transport: 'socket'

Process finished with exit code 0

0 个答案:

没有答案