Running Scenarios

Running Scenarios

JBehave was designed to be embeddable in different development
environments. The jbehave-core contains support for running
scenarios as JUnit tests – which can be run either in your favourite IDE
or in your command-line build that supports JUnit tests.

You can also run scenarios using the JBehave Ant or Maven
extensions. Both support two way to lookup scenarios, by list of
scenario classes or by Java path includes/excludes pattern. Below are
examples on how to configure both extensions – using the trader example.

Running as Ant task

  <taskdef name="scenarioRunner"
    classname="org.jbehave.ant.ScenarioRunnerTask"
    classpathref="your.runtime.classpath" />
 
  <scenarioRunner 
   scenarioClassNames="org.jbehave.examples.trader.scenarios.StatusAlertCanBeActivated,
                                   org.jbehave.examples.trader.scenarios.StatusAlertCanBeActivated" />
 
  <scenarioRunner
    scenarioIncludes="org/jbehave/examples/trader/scenarios/*.java"
    scenarioExcludes="**/*Steps.java" />

Remember that you need to include jbehave-ant to your
runtime classpath.

Running as Maven Plugin

   <plugin>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>run-scenarios-listed</id>
            <phase>integration-test</phase>
            <configuration>
              <scenarioClassNames>                
 
<scenarioClassName>org.jbehave.examples.trader.scenarios.StatusAlertCanBeActivated</scenarioClassName>               
 
<scenarioClassName>org.jbehave.examples.trader.scenarios.StatusAlertIsNeverActivated</scenarioClassName>
              </scenarioClassNames>
            </configuration>
            <goals>
              <goal>run-scenarios</goal>
            </goals>
          </execution>
          <execution>
            <id>run-scenarios-found</id>
            <phase>integration-test</phase>
            <configuration>
              <scenarioIncludes>
                <scenarioInclude>org/jbehave/examples/trader/scenarios/*.java</scenarioInclude>
              </scenarioIncludes>
              <scenarioExcludes>
                <scenarioExclude>**/*Steps.java</scenarioExclude>
              </scenarioExcludes>
            </configuration>
            <goals>
              <goal>run-scenarios</goal>
            </goals>
          </execution>
        </executions>
    </plugin>

Scenario Scope

By default, the scenario lookup occurs at “compile” scope, i.e. in the main source directory, which defaults to src/main/java (but is configurable in both Ant and Maven) via the Task or POM sourceDirectory property.

Alternately, users may want to run scenarios in “test” scope, which looks up scenario in test source directory, which defaults to src/test/java (but is configurable in both Ant and Maven) via the Task or POM testSourceDirectory property.

To set the scope in Ant

  <scenarioRunner
    scenarioIncludes="org/jbehave/examples/trader/scenarios/*.java"
    scenarioExcludes="**/*Steps.java" 
    scope="test"/>
and in Maven
   <plugin>
        <groupId>org.jbehave</groupId>
        <artifactId>jbehave-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>run-scenarios-found</id>
            <phase>integration-test</phase>
            <configuration>
              <scenarioIncludes>
                <scenarioInclude>org/jbehave/examples/trader/scenarios/*.java</scenarioInclude>
              </scenarioIncludes>
              <scenarioExcludes>
                <scenarioExclude>**/*Steps.java</scenarioExclude>
              </scenarioExcludes>
              <scope>test</scope>
            </configuration>
            <goals>
              <goal>run-scenarios</goal>
            </goals>
          </execution>
        </executions>
    </plugin>