额外的记录JBehave

场景是这样的:

我们使用JBehave和Selenium进行系统,集成和端到端测试。 我正在检查超过20个值的页面上的计算结果以进行validation。 使用Junit断言整个测试将在其中一个值不正确的第一个实例上失败。 我想要做的是,如果一个断言失败,那么测试继续执行,这样我就可以在一次测试运行中整理所有不正确的值,而不是多次测试运行。

为此,我捕获断言并将未通过validation的任何内容写出到日志文件中。 这给我留下了几个问题:

1)我写出断言失败的日志文件不包含发生exception时正在运行的JBehave Story或Scenario的名称。

2)JBehave Story或Scenario被列为’通过’,我希望它被列为’失败’。

有没有办法可以将Story和Scenario的名称记录到附加日志文件中,或者将其他日志记录写入JBehave日志文件?

如何将Story / Scenario标记为失败?

在JBehave配置中,我有:

configuredEmbedder() .embedderControls() .doIgnoreFailureInStories(true) .doIgnoreFailureInView(false) .doVerboseFailures(true) .useStoryTimeoutInSecs(appSet.getMaxRunningTime()); 

 .useStoryReporterBuilder( new StoryReporterBuilder() .withDefaultFormats() .withViewResources(viewResources) .withFormats(Format.HTML, Format.CONSOLE) .withFailureTrace(true) .withFailureTraceCompression(true) .withRelativeDirectory("jbehave/" + appSet.getApplication()) 

是的,您可以创建自己的StoryReporter:

  public class MyStoryReporter implements org.jbehave.core.reporters.StoryReporter{ private Log log = ... @Override public void successful(String step) { log.info(">>successStep:" + step); } @Override public void failed(String step, Throwable cause) { log.error(">>error:" + step + ", reason:" + cause); } ... } 

并注册如下:

 .useStoryReporterBuilder( new StoryReporterBuilder() .withReporters(new MyStoryReporter()) ..