- Revision
- 1455
- Author
- mauro
- Date
- 2009-12-22 14:54:55 -0600 (Tue, 22 Dec 2009)
Log Message
JBEHAVE-165: Added batch mode in running scenarios via Ant and Maven. Added non_successful.scenario to show how batch and ignore failure modes can be used to generate a complete scenario report with successful, failed and pending steps.
Modified Paths
- trunk/core/examples/trader/build.xml
- trunk/core/examples/trader/pom.xml
- trunk/core/examples/trader-test-scope/pom.xml
- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java
- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java
Added Paths
Diff
Modified: trunk/core/examples/trader/build.xml (1454 => 1455)
--- trunk/core/examples/trader/build.xml 2009-12-22 18:38:27 UTC (rev 1454) +++ trunk/core/examples/trader/build.xml 2009-12-22 20:54:55 UTC (rev 1455) @@ -64,7 +64,9 @@ classpathref="scenario.classpath" /> <scenarioRunner scenarioIncludes="**/scenarios/*.java" sourceDirectory="${basedir}/src/main/java" - scenarioExcludes="**/i18n/scenarios/*.java" classLoaderInjected="false" /> + scenarioExcludes="**/scenarios/NonSuccessful.java,**/i18n/scenarios/*.java" batch="true" ignoreFailure="false" classLoaderInjected="false" /> + <scenarioRunner scenarioIncludes="**/scenarios/*.java" sourceDirectory="${basedir}/src/main/java" + scenarioExcludes="**/i18n/scenarios/*.java" batch="true" ignoreFailure="true" classLoaderInjected="false" /> <scenarioRunner scenarioIncludes="**/i18n/scenarios/*.java" sourceDirectory="${basedir}/src/main/java" scenarioExcludes="" classLoaderInjected="true" /> </target>
Modified: trunk/core/examples/trader/pom.xml (1454 => 1455)
--- trunk/core/examples/trader/pom.xml 2009-12-22 18:38:27 UTC (rev 1454) +++ trunk/core/examples/trader/pom.xml 2009-12-22 20:54:55 UTC (rev 1455) @@ -79,9 +79,12 @@ <scenarioInclude>**/scenarios/*.java</scenarioInclude> </scenarioIncludes> <scenarioExcludes> + <scenarioExclude>**/scenarios/NonSuccessful.java</scenarioExclude> <scenarioExclude>**/i18n/scenarios/*.java</scenarioExclude> </scenarioExcludes> <skip>false</skip> + <batch>false</batch> + <ignoreFailure>false</ignoreFailure> <classLoaderInjected>false</classLoaderInjected> </configuration> <goals> @@ -89,6 +92,25 @@ </goals> </execution> <execution> + <id>run-scenarios-in-batch-mode</id> + <phase>integration-test</phase> + <configuration> + <scenarioIncludes> + <scenarioInclude>**/scenarios/*.java</scenarioInclude> + </scenarioIncludes> + <scenarioExcludes> + <scenarioExclude>**/i18n/scenarios/*.java</scenarioExclude> + </scenarioExcludes> + <skip>false</skip> + <batch>true</batch> + <ignoreFailure>true</ignoreFailure> + <classLoaderInjected>false</classLoaderInjected> + </configuration> + <goals> + <goal>run-scenarios</goal> + </goals> + </execution> + <execution> <id>run-i18n-scenarios-found</id> <phase>integration-test</phase> <configuration>
Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/NonSuccessful.java (0 => 1455)
--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/NonSuccessful.java (rev 0) +++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/NonSuccessful.java 2009-12-22 20:54:55 UTC (rev 1455) @@ -0,0 +1,11 @@ +package org.jbehave.examples.trader.scenarios; + +import org.jbehave.examples.trader.TraderScenario; + +public class NonSuccessful extends TraderScenario { + + public NonSuccessful() { + super(NonSuccessful.class); + } + +} \ No newline at end of file
Added: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/non_successful.scenario (0 => 1455)
--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/non_successful.scenario (rev 0) +++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/scenarios/non_successful.scenario 2009-12-22 20:54:55 UTC (rev 1455) @@ -0,0 +1,23 @@ +Scenario: A scenario with failed step + +Given the traders: +|name|rank| +|Larry|Stooge 3| +|Moe|Stooge 1| +|Curly|Stooge 2| +When a wildcard search ".*y" is executed +Then the traders returned are: +|name|rank| +|Moe|Stooge 1| + +Scenario: An scenario with pending and non executed steps + +Given the traders: +|name|rank| +|Larry|Stooge 3| +|Moe|Stooge 1| +|Curly|Stooge 2| +When a search ".*y" is executed +Then the traders returned are: +|name|rank| +|Moe|Stooge 1|
Modified: trunk/core/examples/trader-test-scope/pom.xml (1454 => 1455)
--- trunk/core/examples/trader-test-scope/pom.xml 2009-12-22 18:38:27 UTC (rev 1454) +++ trunk/core/examples/trader-test-scope/pom.xml 2009-12-22 20:54:55 UTC (rev 1455) @@ -23,10 +23,11 @@ <phase>integration-test</phase> <configuration> <scenarioIncludes> - <scenarioInclude>org/jbehave/examples/trader/scenarios/*.java</scenarioInclude> + <scenarioInclude>**/scenarios/*.java</scenarioInclude> </scenarioIncludes> <scenarioExcludes> - <scenarioExclude>**/*Steps.java</scenarioExclude> + <scenarioExclude>**/i18n/scenarios/*.java</scenarioExclude> + <scenarioExclude>**/NonSuccessful.java</scenarioExclude> </scenarioExcludes> <skip>false</skip> <scope>test</scope>
Modified: trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java (1454 => 1455)
--- trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java 2009-12-22 18:38:27 UTC (rev 1454) +++ trunk/core/jbehave-ant/src/main/java/org/jbehave/ant/ScenarioRunnerTask.java 2009-12-22 20:54:55 UTC (rev 1455) @@ -3,6 +3,9 @@ import static org.apache.tools.ant.Project.MSG_INFO; import static org.apache.tools.ant.Project.MSG_WARN; +import java.util.HashMap; +import java.util.Map; + import org.apache.tools.ant.BuildException; import org.jbehave.scenario.RunnableScenario; @@ -13,25 +16,60 @@ */ public class ScenarioRunnerTask extends AbstractScenarioTask { + /** + * The boolean flag to run in batch mode + */ + private boolean batch; + public void execute() throws BuildException { if (skipScenarios()) { log("Skipped running scenarios", MSG_INFO); return; } + + Map<String, Throwable> failedScenarios = new HashMap<String, Throwable>(); for (RunnableScenario scenario : scenarios()) { String scenarioName = scenario.getClass().getName(); try { log("Running scenario " + scenarioName); scenario.runScenario(); } catch (Throwable e) { - String message = "Failed to run scenario " + scenarioName; - if (ignoreFailure()) { - log(message, e, MSG_WARN); + String message = "Failure in running scenario " + scenarioName; + if (batch) { + // collect and postpone decision to throw exception + failedScenarios.put(scenarioName, e); } else { - throw new BuildException(message, e); + if (ignoreFailure()) { + log(message, e, MSG_WARN); + } else { + throw new BuildException(message, e); + } } } } + if (batch && failedScenarios.size() > 0) { + String message = "Failure in runing scenarios: " + format(failedScenarios); + if (ignoreFailure()) { + log(message, MSG_WARN); + } else { + throw new BuildException(message); + } + } } + private String format(Map<String, Throwable> failedScenarios) { + StringBuffer sb = new StringBuffer(); + for (String scenarioName : failedScenarios.keySet()) { + Throwable cause = failedScenarios.get(scenarioName); + sb.append("\n"); + sb.append(scenarioName); + sb.append(": "); + sb.append(cause.getMessage()); + } + return sb.toString(); + } + + public void setBatch(boolean batch) { + this.batch = batch; + } }
Modified: trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java (1454 => 1455)
--- trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java 2009-12-22 18:38:27 UTC (rev 1454) +++ trunk/core/jbehave-maven-plugin/src/main/java/org/jbehave/mojo/ScenarioRunnerMojo.java 2009-12-22 20:54:55 UTC (rev 1455) @@ -4,33 +4,74 @@ import org.apache.maven.plugin.MojoFailureException; import org.jbehave.scenario.RunnableScenario; +import java.util.HashMap; +import java.util.Map; + /** * Mojo to run scenarios - * + * * @author Mauro Talevi * @goal run-scenarios */ public class ScenarioRunnerMojo extends AbstractScenarioMojo { - + + /** + * The boolean flag to run in batch mode + * + * @parameter default-value="false" + */ + private boolean batch; + public void execute() throws MojoExecutionException, MojoFailureException { - if ( skipScenarios() ){ + if (skipScenarios()) { getLog().info("Skipped running scenarios"); return; } + + Map<String, Throwable> failedScenarios = new HashMap<String, Throwable>(); for (RunnableScenario scenario : scenarios()) { String scenarioName = scenario.getClass().getName(); try { - getLog().info("Running scenario " + scenarioName); + getLog().info("Running scenario " + scenarioName); scenario.runScenario(); } catch (Throwable e) { - String message = "Failed to run scenario " + scenarioName; - if ( ignoreFailure() ){ - getLog().warn(message, e); + String message = "Failure in running scenario " + scenarioName; + if (batch) { + // collect and postpone decision to throw exception + failedScenarios.put(scenarioName, e); } else { - throw new MojoExecutionException(message, e); + if (ignoreFailure()) { + getLog().warn(message, e); + } else { + throw new MojoExecutionException(message, e); + } } } } + + if (batch && failedScenarios.size() > 0) { + String message = "Failure in runing scenarios: " + format(failedScenarios); + if ( ignoreFailure() ){ + getLog().warn(message); + } else { + throw new MojoExecutionException(message); + } + } + } + private String format(Map<String, Throwable> failedScenarios) { + StringBuffer sb = new StringBuffer(); + for (String scenarioName : failedScenarios.keySet()) { + Throwable cause = failedScenarios.get(scenarioName); + sb.append("\n"); + sb.append(scenarioName); + sb.append(": "); + sb.append(cause.getMessage()); + } + return sb.toString(); + } + } + +
To unsubscribe from this list please visit:
