JBehave comes with some very comprehensive examples, so I thought I’d start there to see if I could get one of them building – and reporting – under Maven. The example I chose was the ‘trader‘ example, which you can see at github.
I chose the trader example because it’s the base example for most of the others that they have, so it seemed a logical beginning point. So, the first thing I did was exported it into my spike repo.
(These links are links to the state of the repository at the commit mentioned, BTW)
Well, it didn’t run, and I didn’t expect it to. The examples in jbehave run as part of their build, and I wanted something standalone. To achieve that, I needed to do the following:
- Removed the reference to the parent.
- Re-defined a bunch of properties, lifted from the old parent.
- Added the dependency to jbehave-core so things would compile.
- Defined the plugin version to use and set up the test execution proper. (The plugin-management is overkill, but that’s what the old parent did, so I’ve reproduced it; this spike is about making things work, not improving)
- Told Maven to treat the Java source directory like a resource directory, because that’s where the stories lived.
At this point, I could run the build and produce reports. But the HTML reports had references to static resources (little things – like CSS, images, and Javascript) that made them useless with out it. So I brought in some more things from the old parent:
- I configured a step in the process-resources phase to unpack view resources
- I then added some extra dependencies to provide those view resources
The build now produces pretty reports! And there was much rejoicing!
You can see the whole thing under the ‘maven_reports_showing’ tag.
Actually, no there wasn’t any rejoicing. This isn’t anywhere near satisfactory to me. Some of it is just my usual gripes with Maven and its verbosity, and can be solved through better use of parent POMs to provide defaults (for example – the plugin configuration can be pulled into a parent, as could the view resource dependencies, which can be dependencies of the plugin instead of the project – possibly). But the biggest problem I’ve got with this is that the stories – and their supporting code – are in the prod code section. That’s going to have to change.
However, all of that is part of a different adventure – this one ends here, having achieved the minimal goal of “run and report under Maven”.
As a Java & JBehave nooob, I’m so happy that you’re doing this !
Thank you. I am continuing the series, but the next example (using Spring) is a little more complicated and my time has been somewhat constrained lately.