Running easyb
easyb can be invoked via:
Command line
easyb comes with a command line runner that takes the name of a particular behavior or story you wish to run. You can optionally pass in a few different flag options to output various report formats as well.
c:>java org.disco.easyb.BehaviorRunner my/path/to/MyStory.groovy
If no additional arguments are specified, you'll see a report printed to System.out that looks something
like this:
Running your story (Your.story)
Scenarios run: 1, Failures: 0, Pending: 0, Time Elapsed: 0.454 sec
1 behavior run with no failures
Want to run multiple behaviors or stories in a single run? Yep, easyb supports that too. Just pass multiple stories on the command line.
c:>java org.disco.easyb.BehaviorRunner my/path/to/MyStory.groovy my/path/to/MySecondStory.groovy
Note, the runner doesn't care if you run a specification or a story-- they are run the same either way! Easy, eh?
Story reporting via the command line
You can generate a story printout of an easyb story by passing in the -txtstory flag as follows:
c:>java org.disco.easyb.BehaviorRunner my/path/to/MyStory.groovy \
-txtstory ./target/mystory.txt
Note, the line break in the above example is for formatting purposes only.
XML reporting via the command line
If you'd rather produce an XML report, just pass in the -xmleasyb flag and provide a path where the xml
report should be written. For instance, using the same example from earlier, if you'd rather have an XML report,
simply type:
c:>java org.disco.easyb.BehaviorRunner my/path/to/MyStory.groovy \
-xmleasyb my/path/report.xml
Note, the line break in the above example is for formatting purposes only.
Ant
You can run your behaviors and stories via easyb's Ant task. It's easy:
- load the task (via Ant's
taskdef)-- the class name isorg.disco.easyb.ant.BehaviorRunnerTask - provide a location for a report (or series of reports) and then provide a
filesetwith the location(s) of your behaviors and stories
Defining the task looks like this:
<taskdef name="easyb" classname="org.disco.easyb.ant.BehaviorRunnerTask">
<classpath>
<pathelement location="${lib.dir}/release/easyb-xx.jar"/>
</classpath>
</taskdef>
Running the task looks like:
<easyb>
<classpath>
<path refid="build.classpath" />
<pathelement path="target/classes" />
</classpath>
<report location="target/story.txt" format="txtstory" />
<behaviors dir="${mybehaviors.dir}">
<include name="**/*Story.groovy"/>
</behaviors>
</easyb>
Produces output:
[easyb] Running story listener story (StoryListener.story)
[easyb] Scenarios run: 2, Failures: 0, Pending: 0, Time Elapsed: 0.06 sec
[easyb] 2 total behaviors run with no failures
[easyb] easyb execution passed
BUILD SUCCESSFUL
Total time: 3 seconds
Failures
The point of having your behaviors run as part of your build is to notify you when they catch possible code problems. easyb also allows a user specified property to be set to true if the build fails.
This property is called failureProperty and using it would look like this
<easyb failureProperty="easyb.failed">
That alone doesn't fail the build but puts the flexibility in your hands to fail it, print it or do nothing with it as you please. Here is a common example of using that property to fail a build:
<fail if="easyb.failed" message="Execution halted as behaviors failed"/>
Now when a behavior fails our build will halt with output like so:
[easyb] easyb is preparing to process 1 file(s)
[easyb] 9 behavior steps run , but status is failure! Total failures: 1
[easyb] Failure -> then the dealer should win in BlackjackStory.groovy
[easyb] VerificationException: expected lossss but was loss:
....
....
[easyb] specification failures detected!
[easyb] easyb execution FAILED
BUILD FAILED
/blah/blah/build.xml:75: easyb reported a failure
Total time: 3 seconds
Now you can be more confident that your build hasn't been broken by a change since you get instant feedback on behavior failures.
Story Printing
easyb embraces the idea that stories are a link between the business requirements and your code. To help use those stories when talking to your clients about requirements, easyb provides a way to print out just the stories without a lot of geeky code.
To print out a story report via Ant, simply create a report element with its format attribute set to txtstory as follows:
<report location="target/stories.txt" format="txtstory"/>
Here is some sample output:
9 behavior steps executed successfully
Story: blackjack
scenario tie game when cards are dealt but dealer gets higher card
given a game a blackjack game and both players have a score of 10
when the dealer gets an Ace and you get a 10
then the dealer should win
scenario tie game when cards are dealt but player gets higher card
given a game a blackjack game and both players have a score of 10
when the dealer gets a 10 and you get an Ace
then the player should win
That looks like something business users (or management) could understand-- they might even be able to *gasp* write them!
Maven
You can also run your behaviors and stories via easyb's Maven plugin as well as generate HTML story reports. It's easy as fully explained on the maven-easyb-plugin site. Just take note that it may take a couple of days for easyb to get uploaded to maven central. In the meantime you can use the easyb repository by adding this snippet to your pom:
<project>
...
<repositories>
<repository>
<id>easyb</id>
<url>http://www.easyb.org/repo/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>easyb</id>
<url>http://www.easyb.org/repo/</url>
</pluginRepository>
</pluginRepositories>
...
</project>
NOTE The repositories listed above are not browseable. This means that you (and maven) can view individual file but if you simply navigate to the top of the repository you will get a permission error.
IntelliJ
We have created an easyb plugin for IntelliJ that makes it super easyb to work with easyb specifications and to run and debug them. This plugin can be downloaded from easyb-plugin-0.8.1.zip and installing is as easyb as uncompressing this zip file into your IntelliJ plugin directory.
NOTE The current version of the easyb plugin for IntelliJ doesn't set file associations correctly. This can cause easyb stories and specifications to disappear from the IDE or be run as if they were groovy scripts. You can workaround this behavior by following these steps:
- Open the IntelliJ settings dialog
- Select File Types
- Locate the "easyb story" file type and remove all associations
- Locate the "Groovy Scripts and Classes" file type and add ".story", "*Story.groovy", ".specification", and "*Specification.groovy"
NOTE Also, with the current version of the plugin you will need to make easyb available on the classpath of your project. The next release of the plugin will make this unnecessary.