尽管我看了很多篇关于如何使用 JBehave 的文章,但我却无法使它正常工作。以下是我迄今为止所进行的步骤:
- 创建了一个新的 Java 项目
- 下载了 JBehave JAR 文件版本 3.6.8 并将其添加到我的构建路径库中
- 在测试源文件夹下创建了一个名为
com.wmi.tutorials.bdd.stack.specs
的包 - 将 JBehave JAR 文件添加到我的 Build path Library 配置中
- 在上述包中创建了一个 JBehave story(StackBehaviourStories.story)
- 在上述包中创建了一个 Java 类(StackBehaviourStory.java)
- 在上述包中创建了一个 Java 类(StackBehaviourSteps.java)
- 在我的 Java 类中导入了 Given、Named、Then、When 注解
- 在我的 JBehave story 文件中编写了两个不同的场景
然而,我仍然无法让它工作/运行!=(
故事文件:
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
故事类
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());
}
}
步骤类
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);
}
}
我目前使用的是 Eclipse Kepler (4.3) JEE 版本,已经安装了我需要使用的 JUnit、Google App Engine,而且是按照 Eclipse JBehave 安装教程正确安装了 JBehave。
但是我无法让它正常工作。那么我该如何在 Eclipse 中正确地使用 JBehave 和 JUnit?