【问题标题】:JBehave HTML reports - How to display how many stories runJBehave HTML 报告 - 如何显示运行的故事数
【发布时间】:2017-09-08 14:55:16
【问题描述】:

在 JBehave 的默认 HTML Story Reports 中,它显示了运行了多少个 Scenarios,有多少个 GiventStory Scenarios 和多少个步骤。

我尝试做的是在其上添加一些信息以显示运行了多少故事。

例如,如果我有一个包含 3 个示例的场景,它将运行 3 个故事。实际上它在表格中只显示一个场景,我想要一个新列来记录运行的 3 个故事。

是我的实际配置:

public class JBehaveStoryRunner extends JUnitStories {

    @Autowired
    private ApplicationContext applicationContext;

    public JBehaveStoryRunner() {
        Class<?> thisClass = this.getClass();
        Properties properties = new Properties();
        properties.setProperty("encoding", "UTF-8");
        // @formatter:off
        useConfiguration(new MostUsefulConfiguration()
                .useStoryLoader(new LoadFromClasspath(thisClass.getClassLoader()))
                .usePendingStepStrategy(new FailingUponPendingStep())
                .useStepdocReporter(new PrintStreamStepdocReporter())
                .useStoryReporterBuilder(new StoryReporterBuilder()
                        .withCodeLocation(CodeLocations.codeLocationFromClass(thisClass))
                        .withDefaultFormats()
                        .withFormats(Format.CONSOLE, Format.TXT, Format.HTML, Format.XML, Format.STATS)
                        .withCrossReference(new CrossReference())
                        .withViewResources(properties)
                        .withFailureTrace(true))
                .useParameterConverters(new ParameterConverters()
                        .addConverters(new ParameterConverters.DateConverter(new SimpleDateFormat("dd-MM-yyyy"))))
                .useStoryParser(new GherkinStoryParser())
                .useParameterControls(new ParameterControls().useNameDelimiterLeft("[").useNameDelimiterRight("]"))
                .useStepMonitor(new SilentStepMonitor()));
        // @formatter:on
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new SpringStepsFactory(configuration(), applicationContext);
    }

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

【问题讨论】:

    标签: java jbehave


    【解决方案1】:

    此 HTML 报告是使用 this (jbehave-reports.ftl) Freemaker 模板创建的。如果您想在此报告中添加新字段,您需要自定义此模板,或创建您自己的副本。

    我个人会使用使用 XML 文件(在您的配置中使用 Format.XML 时生成),因为我不了解 Freemaker,也没有时间学习它。
    XML 文件包含您需要的所有信息,只需对其进行解析并计算要在报告中显示的元素。

    这是为以下示例故事生成的数据示例(在基于 maven 的项目中:jbehave-simple-archetype):

    Scenario: A scenario with some pending steps
    
    Given I am a pending step <Step>
    When a good soul will implement me
    Then I shall be happy <Val>
    Examples:
    |Step|Val|
    |1|1|
    |2|2|
    

    <story path="org/irko/my_jbehave_simple/stories/my.story" title="">
        <scenario keyword="Scenario:" title="A scenario with some pending steps">
            <examples keyword="Examples:">
                <step>Given I am a pending step &lt;Step&gt;</step>
                <step>When a good soul will implement me</step>
                <step>Then I shall be happy &lt;Val&gt;</step>
                <parameters>
                    <names>
                        <name>Step</name>
                        <name>Val</name>
                    </names>
                    <values>
                        <value>1</value>
                        <value>1</value>
                    </values>
                    <values>
                        <value>2</value>
                        <value>2</value>
                    </values>
                </parameters>
    
                <example keyword="Example:">{Step=1, Val=1}</example>
                <step outcome="successful">
                    Given I am a pending step
                    <parameter>1</parameter>
                </step>
                <step outcome="successful">When a good soul will implement me</step>
                <step outcome="successful">
                    Then I shall be happy
                    <parameter>1</parameter>
                </step>
    
                <example keyword="Example:">{Step=2, Val=2}</example>
                <step outcome="successful">
                    Given I am a pending step
                    <parameter>2</parameter>
                </step>
                <step outcome="successful">When a good soul will implement me</step>
                <step outcome="successful">
                    Then I shall be happy
                    <parameter>2</parameter>
                </step>
            </examples>
        </scenario>
    </story>
    

    【讨论】:

    • 这是我认为的一种方式,但我希望有一种更简单的方式:-P
    猜你喜欢
    • 2011-09-07
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多