JBehave HTML 报告 - 如何显示多少故事 运行
JBehave HTML reports - How to display how many stories run
在默认的HTML JBehave Story Reports中,它显示了多少个Scenarios运行,多少个GiventStory Scenarios和多少个步骤。
我尝试做的是在上面添加一些信息以显示 运行.
中有多少故事
例如,如果我有一个包含 3 个示例的场景,它将 运行 3 个故事。实际上它在 table 中只显示一个场景,我想要一个新的专栏来显示 运行.
的 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");
}
}
此 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>
在默认的HTML JBehave Story Reports中,它显示了多少个Scenarios运行,多少个GiventStory Scenarios和多少个步骤。
我尝试做的是在上面添加一些信息以显示 运行.
中有多少故事例如,如果我有一个包含 3 个示例的场景,它将 运行 3 个故事。实际上它在 table 中只显示一个场景,我想要一个新的专栏来显示 运行.
的 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");
}
}
此 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>