java - 无法运行 JBehave 故事

标签 java maven jbehave

有人可以帮我运行一个 JBehave 故事吗?我在 Eclipse 中有一个 Maven 项目。

故事是:

Meta:
@author Nikolay Vasilev
@bdd-talk: BG JUG

Scenario:  Validating BMI calculator

Given a body mass index calculator
When a doctor populates health record of a patient with mass 90 kg and 175 cm tall
Then patient's body mass index is 23

保存在src/test/resources/stories中,体现在pom.xml中:

<build>
    <testResources>
        <testResource>
            <directory>src/test/resources/stories</directory>
        </testResource>
    </testResources>
    ...

步骤类是:

public class MetricBMICalculatorSteps {
    private HealthRecord healthRecord;
    private MetricBMICalculator bmiCalculator;
    private BodyMassIndex bmi;

    @Given("a body mass index calculator")
    public void initBMICalculator() {
        bmiCalculator = new MetricBMICalculator();
    }

    @When("a doctor populates health record of a patient with mass $weight kg and $height cm tall")
    public void populateHealthRecord(@Named("weight") float weight, @Named("height") float height) {
        healthRecord = new ISUHealthRecord();
        healthRecord.setWeight(weight);
        healthRecord.setHeight(height);
        bmi = bmiCalculator.calculate(healthRecord);
    }

    @Then("Then patient's body mass index is $bmi")
    public void checkBmi(@Named("bmi") double bmiValue) {
        Assert.assertEquals(bmiValue, bmi.value());
    }
}

我的嵌入器是:

public class MyEmbedder extends Embedder {

    // --- Constants -----------------------------------------------------------

    private Configuration configuration;

    // --- Constructors --------------------------------------------------------

    public MyEmbedder() {
        configuration = loadConfiguration();
    }

    // --- Methods -------------------------------------------------------------

    @Override
    public Configuration configuration() {
        return configuration;
    }

    // Here we specify the steps classes
    @Override
    public List<CandidateSteps> candidateSteps() {
        // varargs, can have more that one steps classes
        return new InstanceStepsFactory(configuration(), new MetricBMICalculatorSteps()).createCandidateSteps();
    }

    // --- Methods (Auxiliary) -------------------------------------------------

    private Configuration loadConfiguration() {
        Configuration configuration = new MostUsefulConfiguration();
        configuration.useStoryLoader(loadStoryLoader());
        configuration.useStoryReporterBuilder(loadStoryReporterBuilder());
        configuration.useStepMonitor(new SilentStepMonitor());

        return configuration;
    }

    // where to find the stories
    private StoryLoader loadStoryLoader() {
        return new LoadFromRelativeFile(
                CodeLocations.codeLocationFromClass(this.getClass()));
    }

    private StoryReporterBuilder loadStoryReporterBuilder() {
        // CONSOLE and TXT reporting
        StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder();
        storyReporterBuilder.withDefaultFormats();
        storyReporterBuilder.withFormats(Format.CONSOLE, Format.TXT);
        return storyReporterBuilder;
    }

    public void runStory(String story) {
        if (story != null && story.endsWith(".story")) {
            this.runStoriesAsPaths(Arrays.asList(story));
        } else {
            throw new RuntimeException("Problem locating .story file:" + story);
        }
    }
}

当我尝试运行它时:

String storyRelativePath = "health/steps/MetricBMICalculator.story";
MyEmbedder eclipseEmbedder = new MyEmbedder(storyRelativePath);
eclipseEmbedder.runStory(storyRelativePath);

在我看来,步骤文件根本没有执行(至少在调试期间,执行不会在我放置的步骤类中的断点处停止)。这是执行的输出:

Processing system properties {}

(BeforeStories)
Using 1 threads
Running story health/steps/MetricBMICalculator.story

(AfterStories)
Generating reports view to 'D:\workspace\bg-jug-bdd\jug-bdd-jbehave-maven\target\jbehave'

using formats `[stats, console, txt]`

and view properties
{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}
Reports view generated with 2 stories (of which 0 pending)  containing 0 scenarios (of which 0 failed and 0 pending)

有没有人知道我应该做什么才能运行那个故事?

最佳答案

Mauro Talevi 在 a mailing list 中回答了这个问题:

You're missing the stats, which are used in the report generation. You can either invoke withDefaultFormats() on the StoryReporterBuilder, or add Format.STATS directly to withFormats().

关于java - 无法运行 JBehave 故事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6213677/

相关文章:

java - Maven 看不到 jBehave

java - 处理大量 C、Java、Informix

java - 通过接口(interface)将数据从 Activity 传递到服务

java - 当尝试实现我的 Tilemap 时,Java 向我抛出错误 ' For input string: ""'

java - Maven zip 程序集,包括子目录内容

java - 使用 Maven 运行 JBehave 的问题

java - 三点高斯积分程序

Tomcat 似乎没有在我的 WEB-INF/lib 文件夹中提取 jar

java - 找不到符号符号: class NestableRuntimeException location: package org. hibernate.exception

JBehave - 示例表正在执行注释