What is the starting point in JBehave BDD
-
30-04-2021 - |
سؤال
I have gone though the JBehave official docs and have started making a sample project work. I am clear with the 1. Step1 : Write a story 2. Step2 : Map steps to Java
I am stuck in "Configure Stories" step. There are many options like extending JUnitStories, JUnitStory, Embedder etc. Which one to use ? And how can I make a simple configure story class work.
.withFormats(CONSOLE, TXT, HTML, XML)) is deprecated, so what to use in that place ?
Basically if I directly take the code snippet provided, it gives compilation errors.
Could someone help.
The reference link : http://jbehave.org/reference/stable/index.html
المحلول
JUnitStory: provides a one-to-one mapping with the textual story via the StoryPathResolver. JUnitStories: provides a many-to-one mapping with the textual story paths explicitly specified by overriding the storyPaths() method.For your case, extending JUnitStories shall be enough.
For the format, please use it as following: StoryReporterBuilder().withDefaultFormats().withFormats(Format.HTML, Format.CONSOLE);
نصائح أخرى
you need import libs belows
import static org.jbehave.core.reporters.Format.CONSOLE;
import static org.jbehave.core.reporters.Format.HTML_TEMPLATE;
import static org.jbehave.core.reporters.Format.TXT;
import static org.jbehave.core.reporters.Format.XML_TEMPLATE;
I looked into the source code and it seems that there are two methods of the same name, one (deprecated
) declared as withFormats(Format... formats)
and other as
withFormats(org.jbehave.core.reporters.Format... formats)
.
So, in order to use non-depricated
version you should write it like this:
new StoryReporterBuilder()
.withFormats(
org.jbehave.core.reporters.Format.CONSOLE,
org.jbehave.core.reporters.Format.TXT,
org.jbehave.core.reporters.Format.HTML,
org.jbehave.core.reporters.Format.XML );