I am following the below posts for creating a Custom Reporter in my JBehave.
JBehave results displayed on a webpage
Whenever I try to create a class, I am getting the below error.
WebStories.MyStoryReporter is not abstract and does not override abstract method pendingMethods(java.util.List<java.lang.String>) in org.jbehave.core.reporters.StoryReporter
So now I have made the class as abstract
as shown below
public class MyStoryReporter implements org.jbehave.core.reporters.StoryReporter
Now the real problem is I cannot call the MyStoryReporter
from .withReporters
since its an abstract class
.useStoryReporterBuilder(new StoryReporterBuilder()
.withCodeLocation(codeLocationFromClass(embeddableClass))
.withDefaultFormats()
.withFormats(ANSI_CONSOLE, HTML, XML, STATS)
.withFailureTrace(true)
.withReporters(new MyStoryReporter));
I think I am missing some basic things. Can anyone help me in this context.
You need to refresh some basics about java interfaces, abstract clasess and inheritation.
Study these links:
http://docs.oracle.com/javase/tutorial/java/concepts/interface.html
http://docs.oracle.com/javase/tutorial/java/IandI/
https://docs.oracle.com/javase/tutorial/java/IandI/abstract.html
org.jbehave.core.reporters.StoryReporter is an interfce that defines 21 abstract methods: http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/reporters/StoryReporter.html
If you want to implement this interface in some class, you need to provide an implementation for all of these 21 methods in implementing class.
If you don't want to define all methods, but only one (or a few of them), then extend NullStoryReporter class instead of implementing StoryReporter interface. NullStoryReporter provides null (empty) implementation for all StoryReporter methods:
http://jbehave.org/reference/latest/javadoc/core/org/jbehave/core/reporters/NullStoryReporter.html
For example, if you want to use only one method successful
in your custom reporter, just do:
public class MyStoryReporter extends org.jbehave.core.reporters.NullStoryReporter{
@Override
public void successful(String step) {
log.info(">>successStep:" + step);
}
}