很简单的一步一步JBehave设置教程? [英] Very simple step by step JBehave setup tutorial?
问题描述
- 创建新的Java项目
- 下载JBehave JAR文件版本3.6.8并将其添加到我的构建路径库
- 创建一个名为
的包com.wmi.tutorials.bdd.stack.specs
在我的工作区中的测试源文件夹下 - 将JBehave JAR文件添加到我的Build路径库配置
- 在上面创建了一个JBehave故事(StackBehaviourStories.story)
- 在上述包(StackBehaviourStory.java)中创建了一个Java类
- 创建了一个Java类上面提到的包(StackBehaviourSteps.java)
- 导入给定,命名,然后,当我的Java类中的注释
- 写了两个不同的场景在我的JBehave故事文件中
然而,我无法让它工作/运行! =(
故事文件
叙述:
为了学习使用Eclipse的JBehave
作为初级Java开发人员,尽管在.Net和BDD
我想定义一个自定义栈的行为
方案:我将一个项目推到堆栈
给定一个空堆栈
当我推一个项目'橙色'
然后我应该计数1
情景:我从栈中弹出
给定我有一个空堆栈
当我推一个项目'苹果'
我弹出栈
然后我应该计数0
故事类
package com.wmi.tutorials .bdd.stack.specs
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStory;
public class StackBehaviourStory扩展了JUnitStory {
@Overrid e
public配置配置(){return new MostUsefulConfiguration(); }
@Override
public InjectableStepsFactory stepsFactory(){
return new InstanceStepsFactory(configuration()
,new StackBehaviourSteps());
}
}
步骤类
package com.wmi.tutorials.bdd.stack.specs
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.junit.Assert;
public class StackBehaviourSteps {
@Given(我有一个空堆栈)
public void givenIHaveAnEmptyStack(){stack = new CustomStack();
@When(I push a item $ item)
public void whenIPushAnItem(@Named(item)String item){stack.push(item);
@Then(我应该计算$ expected)
public void thenIShouldCount(@Named(expected)int expected){
int actual = stack.count( );
if(actual!= expected)
throw new RuntimeException(expected:+ expected +; actual:+ actual);
}
}
我正在使用Eclipse Kepler(4.3)JEE随着我需要使用JUnit,Google App Engine的所有内容,是的,JBehave在Eclipse JBehave安装教程之后正确安装。
我无法使其正常工作。那么我该如何使用Eclipse,JBehave和JUnit来正常工作?
紧跟着一步一步 jbehave入门指南
教程,运行故事部分说: [...] ICanToggleACell.java类将允许自己作为JUnit测试运行。
这意味着您的Build路径中需要JUnit库。
使用Eclipse:
- 选择您当前的项目,然后右键单击它,构建路径,配置构建路径...
- 属性对于 [当前项目] , Java构建路径,库,单击 [添加库...] li>
- 添加库,选择 JUnit ,单击 [Next]
- JUnit库,JUnit库版本,选择您要使用的版本,单击 [完成]
- Java构建路径,单击<确定>
- 项目浏览器,选择您的
ICanToggleACell.java
类,右键单击它,然后单击运行方式,然后单击JUnit测试
所以这里和上面的一样 - 示例代码在将适当的库添加到Java构建路径后, StackBehaviourStory.java
类应该允许自己作为JUnit测试运行。
Though I have read many, but many articles on how to use JBehave, I can't get it to work. Here are the steps I went through so far:
- Created new Java Project
- Downloaded JBehave JAR file version 3.6.8 and added it to my build path libraries
- Created a package called
com.wmi.tutorials.bdd.stack.specs
under the test source folder in my workspace - Added the JBehave JAR file to my Build path Library configuration
- Created a JBehave story in the above-mentioned package (StackBehaviourStories.story)
- Created a Java class in the above-mentioned package (StackBehaviourStory.java)
- Created a Java class in the above-mentioned package (StackBehaviourSteps.java)
- Imported the Given, Named, Then, When annotations in my Java class
- Written two different scenarios in my JBehave story file
And still, I can't get it to work/run! =(
The story file:
Narrative:
In order to learn to with JBehave using Eclipse
As a junior Java developer though senior in .Net and in BDD
I want to define the behaviour of a custom stack
Scenario: I push an item onto the stack
Given I have an empty stack
When I push an item 'orange'
Then I should count 1
Scenario: I pop from the stack
Given I have an empty stack
When I push an item 'apple'
And I pop the stack
Then I should count 0
The story class
package com.wmi.tutorials.bdd.stack.specs
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.junit.JUnitStory;
public class StackBehaviourStory extends JUnitStory {
@Override
public Configuration configuration() { return new MostUsefulConfiguration(); }
@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration()
, new StackBehaviourSteps());
}
}
The steps class
package com.wmi.tutorials.bdd.stack.specs
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.jbehave.core.junit.Assert;
public class StackBehaviourSteps {
@Given("I have an empty stack")
public void givenIHaveAnEmptyStack() { stack = new CustomStack(); }
@When("I push an item $item")
public void whenIPushAnItem(@Named("item") String item) { stack.push(item); }
@Then("I should count $expected")
public void thenIShouldCount(@Named("expected") int expected) {
int actual = stack.count();
if (actual != expected)
throw new RuntimeException("expected:"+expected+";actual:"+actual);
}
}
I'm currently using Eclipse Kepler (4.3) JEE with everything I need to use JUnit, Google App Engine, and yes, JBehave is installed correctly following the Eclipse JBehave installation tutorial.
I can't get it to work. So how can I make it work correctly using Eclipse, JBehave and JUnit?
Following step by step closely the jbehave Getting Started
tutorial, the Run story section says: [...] the ICanToggleACell.java class will allow itself to run as a JUnit test.
This means that the JUnit library is required in your Build path.
Using Eclipse:
- Select your current project and right-click it, Build path, Configure Build Path...
- Properties for [current project], Java Build Path, Libraries, click [Add Library...]
- Add Library, select JUnit, click [Next]
- JUnit Library, JUnit library version, select the version you wish to use, click [Finish]
- Java Build Path, click [OK]
- Project Explorer, select your
ICanToggleACell.java
class, right-click it, then Run As, and click on JUnit Test
So this is the same here as for the above-example code. The StackBehaviourStory.java
class should let itself run as a JUnit test after you add the proper library to the Java build path.
这篇关于很简单的一步一步JBehave设置教程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!