Additional logging JBehave

℡╲_俬逩灬. 提交于 2019-11-30 04:02:11

问题


The scenario is this:

We are using JBehave and Selenium for system, integration and end to end testing. I am checking the results of a calculation on a page with in excess of 20 values to validate. Using Junit Assert the entire test will fail on the first instance of one of the values being incorrect. What I wanted to do was that if an assertion failure is met then the test continues to execute so that I can then collate all of the values that are incorrect in one test run rather than multiple test runs.

To do this I capture the assertions and write out to a log file anything that fails the validation. This has left me with a couple of issues:

1) The log file where I write out the assertions failures do not contain the name of the JBehave Story or Scenario that was being run when the exception occurred.

2) The JBehave Story or Scenario is listed as having 'Passed' and I want it to be listed as 'Failed'.

Is there any way that I can either log the name of the Story and Scenario out to the additional log file OR get the additional logging written to the JBehave log file?

How can I get the Story / Scenario marked as failed?

In the JBehave configuration I have:

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

and

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

回答1:


Yes, you can create your own 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);
    }

     ...
 }

and register it like this:

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


来源:https://stackoverflow.com/questions/11134963/additional-logging-jbehave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!