在JBehave的默认HTML故事报告中,它显示了运行的场景数量,GiventStory场景的数量以及步数。
我尝试做的是在其上添加一些信息,以显示运行的故事数量。
例如,如果我有一个包含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");
}
}
答案 0 :(得分:2)
此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 <Step></step>
<step>When a good soul will implement me</step>
<step>Then I shall be happy <Val></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>