7

我正在尝试创建并运行一个简单的 JUnitStory 来运行一个 .story 文件。

我有这个:

class Scenario1 extends JUnitStory {
    @Delegate MySteps steps = new MySteps()

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration()
                .useStoryLoader(new LoadFromRelativeFile(new File('src/test/groovy').toURL()))
                .useStoryReporterBuilder(
                new StoryReporterBuilder()
                        .withDefaultFormats()
                        .withFormats(Format.HTML, Format.CONSOLE, Format.TXT)

        );
    }

    @Override
    public List candidateSteps() {
        final candidateSteps = new InstanceStepsFactory(configuration(), this).createCandidateSteps()
        return candidateSteps;
    }
}

无论有没有委托(复制和粘贴 MySteps 的所有带注释的方法),每当我运行 JBehave 时,我都会得到以下输出:

somePattern(){
  // PENDING
}

就像个别故事没有跟上步骤一样。

当我创建一个“故事”类并将所有故事文件拉入其中时storyPaths,将定义各个步骤。使用调试器,我看到候选步骤被击中,但它没有提取所需的数据。

这里可能发生了什么?

4

4 回答 4

2

您不需要委托给步骤。而且你不应该覆盖candidateSteps,而应该覆盖stepsFactory。在更高版本的 JBehave 中,不推荐使用 CandidateSteps,以使对工厂方法的偏好更加突出(http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/ConfigurableEmbedder.html#candidateSteps () )

请参阅此博客,其中我更详细地解释了基本 JBehave 配置的工作原理:

http://blog.codecentric.de/en/2012/06/jbehave-configuration-tutorial/

安德烈亚斯

于 2012-06-22T15:05:34.337 回答
1

这是你的答案哥们:格式包已经改变。

这是已弃用的导入静态 org.jbehave.core.reporters.StoryReporterBuilder.Format.HTML;

这是新的 :) import static org.jbehave.core.reporters.Format.HTML;

花了一段时间才找到答案,但隐藏在 jbehave 文档中

希望能帮助到你!干杯!

于 2014-08-07T14:41:05.607 回答
0

您不需要使用 @Delegate - 您的 JUnitStory 不是您的 Steps 类。你可以尝试在你有这个的步骤中传递吗?

当您传入一个已为 Steps 类处理字节码的类时,JBehave 可能不再看到 jbehave 注释。

于 2012-02-24T00:25:18.037 回答
-4

JBehave 是一种陈旧的、不发达的技术。不要使用它。

于 2012-06-18T16:46:18.277 回答