Additional logging JBehave

Gazen Ganados picture Gazen Ganados · Jun 21, 2012 · Viewed 7.2k times · Source

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())

Answer

plasma147 picture plasma147 · Aug 19, 2012

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())
..