apache_maven

jbehave-logo

I won’t explain you how to write any JBehave tests as the online documentation is more than complete.

I prefer to show you how to make them run in eclipse, and in Apache Maven as the example were not easy to run (scenario are wrongly in src/main/java).

 

JBehave is a framework for Behaviour-Driven Development
Behaviour-driven development (BDD) is an evolution of test-driven development (TDD) and acceptance-test driven design, and is intended to make these practices more accessible and intuitive to newcomers and experts alike.
It shifts the vocabulary from being test-based to behaviour-based, and positions itself as a design philosophy.
You can find out more about behaviour-driven development on the BDD wiki, or in the article Introducing BDD

Features of JBehave include:

  • Pure Java implementation, which plays well with Java-based enterprises.
  • Users can specify and run text-based user stories, which allows "out-in" development.
  • Annotation-based binding of textual steps to Java methods, with auto-conversion of string arguments to any parameter type (including generic types) via custom parameter converters.
  • Annotation-based configuration and Steps class specifications
  • Dependency Injection support allowing both configuration and Steps instances composed via your favourite container (Guice, PicoContainer, Spring).
  • Extensible story reporting: outputs stories executed in different human-readable file-based formats (HTML, TXT, XML). Fully style-able view.
  • Auto-generation of pending steps so the build is not broken by a missing step, but has option to configure breaking build for pending steps.
  • Localisation of user stories, allowing them to be written in any language.
  • IDE integration: stories can be run as JUnit tests or other annotation-based unit test frameworks, providing easy integration with your favourite IDE.
  • Ant integration: allows stories to be run via Ant task
  • Maven integration: allows stories to be run via Maven plugin at given build phase

To make the online sample run easily without having to check out the whole tree of JBehave, I will show you that by slightly altering the pom.xml of a sample (Trader), you can run them against a fix version of JBehave.

The whole pom.xml

<profiles>
<profile>
    jbehave
    <activation>
        <activebydefault>false</activebydefault>
    </activation>
    <build>
      <plugins>
        <plugin>
            <groupid>org.apache.maven.plugins</groupid>
            <artifactid>maven-dependency-plugin</artifactid>
            <executions>
                <execution>
                    unpack-jbehave-site-resources
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <overwritereleases>false</overwritereleases>
                        <overwritesnapshots>true</overwritesnapshots>
                        <artifactitems>
                            <artifactitem>
                                <groupid>org.jbehave.site</groupid>
                                <artifactid>jbehave-site-resources</artifactid>
                                <version>2.0.2</version>
                                <outputdirectory>
                                    ${project.build.directory}/jbehave-reports/rendered
                                </outputdirectory>
                            </artifactitem>
                        </artifactitems>
                    </configuration>
                </execution>
                <execution>
                    unpack-jbehave-reports-resources
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <overwritereleases>false</overwritereleases>
                        <overwritesnapshots>true</overwritesnapshots>
                        <artifactitems>
                            <artifactitem>
                                <groupid>org.jbehave</groupid>
                                <artifactid>jbehave-core</artifactid>
                                <version>${jbehave.version}</version>
                                <outputdirectory>
                                    ${project.build.directory}/jbehave-reports/rendered 
                                </outputdirectory>
                                <includes>
                                    **\/*.css,**\/*.ftl,**\/*.js
                                </includes>
                            </artifactitem>
                        </artifactitems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupid>org.jbehave</groupid>
            <artifactid>jbehave-maven-plugin</artifactid>
            <version>${jbehave.version}</version>
            <executions>
                <execution>
                    run-scenarios-found
                    <phase>integration-test</phase>
                    <configuration>
                        <scenarioincludes>
                            <scenarioinclude>
                                **/scenarios/*.java
                            </scenarioinclude>
                        </scenarioincludes>
                        <scenarioexcludes>
                            <scenarioexclude>
                                **/i18n/scenarios/*.java
                            </scenarioexclude>
                        </scenarioexcludes>
                        <batch>false</batch>
                        <ignorefailure>
                            true
                        </ignorefailure>
                        <classloaderinjected>false
                        </classloaderinjected>
                        <scope>test</scope>
                    </configuration>
                    <goals>
                        <goal>run-scenarios</goal>
                    </goals>
                </execution>
                <execution>
                    run-i18n-scenarios-found
                    <phase>integration-test</phase>
                    <configuration>
                        <scenarioincludes>
                            <scenarioinclude>
                                **/i18n/scenarios/*.java
                            </scenarioinclude>
                        </scenarioincludes>
                        <skip>false</skip>
                        <classloaderinjected>
                            true
                        </classloaderinjected>
                        <scope>test</scope>
                    </configuration>
                    <goals>
                        <goal>run-scenarios</goal>
                    </goals>
                </execution>
                <execution>
                    stepdoc
                    <phase>integration-test</phase>
                    <configuration>
                        <scenarioincludes>
                            <scenarioinclude>
                                **/scenarios/*.java
                            </scenarioinclude>
                        </scenarioincludes>
                        <scenarioexcludes>
                            <scenarioexclude>
                                **/scenarios/None.java
                            </scenarioexclude>
                        </scenarioexcludes>
                        <skip>false</skip>
                        <scope>test</scope>
                        <classloaderinjected>false
                        </classloaderinjected>
                    </configuration>
                    <goals>
                        <goal>stepdoc</goal>
                    </goals>
                </execution>
                <execution>
                    render-reports-generated
                    <phase>post-integration-test</phase>
                    <configuration>
                        <formats>
                            <format>txt</format>
                            <format>html</format>
                            <format>xml</format>
                        </formats>
                        <scope>test</scope>
                        <ignorefailure>true</ignorefailure>

                    </configuration>
                    <goals>
                        <goal>render-reports</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        </plugins>
    </build>
  <reporting>
    <excludedefaults>true</excludedefaults>
    <plugins>
        <plugin>
            <groupid>org.jbehave</groupid>
            <artifactid>jbehave-maven-plugin</artifactid>
            <version>${jbehave.version}</version>
            <configuration> </configuration>
            <reportsets>
                <reportset>
                    <reports>
                        <report>render-reports</report>
                    </reports>
                </reportset>
            </reportsets>
        </plugin>
    </plugins>
  </reporting>
</profile>
</profiles>
comments powered by Disqus

You might like also

Fetching artifact programmatically through REST/API in Nexus 3.x
There is so many case where it is desirable to pull down artifact from Sonatype Nexus using REST API, unfortunately Nexus 3.x Rest API are still under development... Some use cases in Nexus 2.x: You have a script that uses REST call to pull down the LATEST maven artifacts every night from Nexus and deploys them. You make extensive use of the REST API in all your puppet modules You use the Atlassian Puppet module for Nexus for creating repository, …
177 Days ago
git-branch-renamer-maven-plugin
When working with many feature/release/bugix/hotfix branches, it is a bad idea to start changing the pom version as this will create merge conflicts using pull request. this plugin allow you to keep in ALL branches the same pom version for all your projects, for example MASTER-SNAPSHOT the version will be derived from branch name automagically :-) You may want to read more first these 2 short articles Update Maven pom version on GIT checkout in TeamCity maven-release-plugin with GIT git-branch-renamer-maven-plugin …
189 Days ago
Review: Getting Started with Apache Maven by Russell Gold
Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was "Getting Started with Apache Maven" http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache Maven. The course is organized in eight chapters, forty videos with a length between two …
1376 Days ago
Update Maven pom version on GIT checkout in TeamCity
Here is a solution to the following problems Deriving Maven artifact version from GIT branch, Update pom version on GIT checkout automatically, Add the ability to use Pull request with Apache Maven. You have a workflow requirement that require you to have the artifact version of a module externally defined from the current branch in GIT. For example You want to start working on a new feature branch “feature-memory-improvement”, so you branch from master a new branch named feature/feature-memory-improvement Having …
1381 Days ago
Easily Compress Web Application Resources with EhCache
Resources such as JavaScript and CSS files can be compressed before being sent to the browser, improving network efficiencies and application load time in certain case. If you are not using Apache with mod_deflate or nginx in front of your web application, you may need to implement resources compression yourself…. Wait! don’t start writing your own filter to compress files like CSS, html, txt, javascript it is way more difficult than you think to properly handle http response headers and …
1863 Days ago
Tomcat 7 and Apache Maven
Here is 3 different way to control the lifetime a local Tomcat 7 container using Apache Maven. A typical scenario would be to start a servlet container prior to running integration tests (Selenium, SAHI or using any other framework you can think of ) With the following examples, you will be able to start an instance of Tomcat 7 running your web application in the pre-integration-test phase and stop the instance in the post-integration-test phase. You can also decide to …
1863 Days ago
Apache Maven copy local file to a remote server server using SSH
I will show you in an Apache Maven configuration file how to copy files to server each time the package phase is executed. Solution with Ant SCP task This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a maven mvn package, you can …
2051 Days ago
Apache M2Eclipse: Get rid of Duplicate resources when opening resources and types
In this small post, I’ll show you how to remove duplicated resources in the Open Resource view of Eclipse Eclipse – M2Eclipse – Subversive …
2057 Days ago
Apache Maven 3 Cookbook
&160; First a big thanks to Packt Publishing for having sent me this book to review! I did enjoy going through this book, while I did not learn a lot of new stuff (I am using Apache Maven daily since 2006!), I found it to be concise and would recommend it anytime to any of my colleagues. But let’s go through my review of this cookbook of over 50 recipes towards optimal Java Software Engineering with Maven 3: Apache Maven
2199 Days ago
Apache Maven 3 Cookbook Review
Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days Grasp the fundamentals and extend Apache Maven 3 to meet your needs Implement engineering practices in your application development process with Apache Maven Collaboration techniques for Agile teams with Apache Maven Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven You …
2245 Days ago