An sbt plugin for running Cucumber features under cuke4duke.
Based on the original cuke4duke-sbt-plugin by rubbish. This implementation upgrades to the latest sbt, cucumber and cuke4duke version and provides more default options. Specifically:
- Works with sbt 0.7.7
- Works with Cucumber 1.0.0
- Works with cuke4duke 0.4.4
- Allows projects compiled and running against Scala 2.8.x and 2.9.x
- Provides three default actions: cucumber, cucumber-dev and cucumber-html
Just run one of the cucumber actions to run all of the cucumber features. Features go in a 'features' directory at the root of the project. Step definitions go in 'src/test/scala'. The following actions are supported:
- cucumber - Runs the cucumber tool with pretty output to the console and source and snippets turned off
- cucumber-dev - Runs the cucumber tool with pretty output to the console and source and snippets turned on
- cucumber-html - Runs the cucumber tool and generates an output cucumber.html file in the target directory
- cucumber-pdf - Runs the cucumber tool and generates an output cucumber.pdf file in the target directory
There are also parameterised versions of each of these tasks (see IMPORTANT NOTE below):
- cuke
- cuke-dev
- cuke-html
- cuke-pdf
Each of these tasks accepts parameter arguments. E.g.: cuke @demo,~@in-progress would run features tagged as @demo and not those tagged as @in-progress. Also: cuke "User admin" would run features with a name matched to "User admin". Multiple arguments can be supplied and honour the following rules:
- arguments starting with @ or ~ will be passed to cucumber using the --tags flag
- arguments starting with anything else will be passed to cucumber using the --name flag
IMPORTANT NOTE: The current design of sbt prevents tasks with parameters (method tasks) being run against the parent project in a multi-module sbt project. This is why there are separate tasks with parameters. To use a parameter task you mush first select a child project. The non-parameter tasks can be run against the parent project or a selected child.
Features are written in text format and are placed in .feature files inside the 'features' directory. For more info on writing features please see the Cucumber website. For example: Feature: Cucumber In order to implement BDD in my Scala project As a developer I want to be able to run Cucumber from with SBT
Scenario: Execute feature with console output
Given A SBT project
When I run the cucumber goal
Then Cucumber is executed against my features and step definitions
Step definitions can be written in Scala, using the cuke4duke Scala DSL. More information on this api can be obtained from the the cuke4duke wiki page for scala. For example: import cuke4duke.{EN, ScalaDsl} import org.scalatest.matchers.ShouldMatchers
class CucumberSteps extends ScalaDsl with EN with ShouldMatchers {
private var givenCalled = false
private var whenCalled = false
Given("""^A SBT project$""") {
givenCalled = true
}
When("""^I run the cucumber goal$""") {
whenCalled = true
}
Then("""^Cucumber is executed against my features and step definitions$""") {
givenCalled should be (true)
whenCalled should be (true)
}
}
In the plugin definition file (project/plugins/Plugin.scala), add the cucumber-sbt-plugin dependency: import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
val templemoreRepo = "templemore sbt repo" at "http://templemore.co.uk/repo"
val cucumberPlugin = "templemore" % "cucumber-sbt-plugin" % "1.1"
}
In your project file (i.e. project/build/TestProject.scala), mixin the CucumberProject trait: import sbt._ import templemore.sbt.CucumberProject
class TestProject(info: ProjectInfo) extends DefaultWebProject(info) with CucumberProject {
// Test Dependencies
val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
//...
}
This trait will all the cuke4duke dependency into your project for use in writing the step definitions.
The plugin supports a number of customisations. The following overrides can be added to your project file to change the behaviour of the plugin:
- jrubyVersion - Allows overriding the version of JRuby that will be used (default: 1.6.1)
- cucumberVersion - Allows overriding the version of Cucumber that will be used (default: 0.10.6)
- cuke4dukeVersion - Allows overriding the version of cuke4duke that will be used (default: 0.4.4)
- picoContainerVersion - Allows overriding the version of PicoContainer used by cuke4duke (default: 2.11.2)
- prawnVersion - Allows overriding the version of the prawn gem that will be used (default 0.8.4)
- featuresDirectory - The location cucumber looks in for feature files (default: info.projectPath / "features")
- reportPath - The directory that will be used for report generation (default: outputPath / "cucumber-report")
- htmlReportPath - The name of the file that the html report will be generated into (default: reportPath / "cucumber.html")
- pdfReportPath - The name of the file that the pdf report will be generated into (default: reportPath / "cucumber.pdf")
- extraCucumberOptions - Allows specifying of additional options to Cucumber, such as tags or names (default: Empty List)
- standardCucumberOptions - Allows overriding the custom options for the 'cucumber' goal (default: --format pretty --no-source --no-snippets)
- devCucumberOptions - Allows overriding the custom options for the 'cucumber-dev' goal (default: --format pretty)
- htmlCucumberOptions - Allows overriding the custom options for the 'cucumber-html' goal (default: --format html --out target/cucumber.html)
- pdfCucumberOptions - Allows overriding the custom options for the 'cucumber-pdf' goal (default: --format pdf --out target/cucumber.pdf)
The plugin supports a number of before and after hooks. These are provided to allow services to be started before cucumber test runs and to shut them down once the test run is complete. The following hooks are provided:
- beforeCucumberSuite and afterCucumberSuite - The default methods that are run. Override these to run custom hooks before/after both the cucumber and cuke tasks
- beforeCucumber and afterCucumber - Override these custom hooks that run before/after only the cucumber tasks (won't be run for cuke tasks)
- beforeCuke and afterCuke - Override these custom hooke that run before/after only the cuke tasks (won't be run for cucumber tasks). These have access to the tag and name parameters passed to the task.
No further work will be undertaken on this plugin. A new version for xsbt 0.10 and above is in development.
Final release of this version of the plugin. All new developments will be against the new 0.10 and above versions of sbt.
- Updated to Cucumber 1.0.0 which was released a couple of days after I made the 1.0 release
Final release of this version of the plugin. All new developments will be against the new 0.10 and above versions of sbt.
- Updated to run using JRuby 1.6.1, Cucumber 0.10.6 and Cuke4Duke 0.4.4
- Updated to run using JRuby 1.6.0.RC3 as the old gem system version in JRuby 1.5.6 was causing a number of problems downloading gems on Windows 7/Vista
- Added debug level logging to JRuby call if SBT logger level is set to debug
- Added lifecycle methods that are run before and after cucumber feature executions
- Renamed all the parameterised cucumberp tasks to be cuke instead as this is more in keeping with the Cucumber project naming style
- Tested with Scala 2.8.1 and SBT 0.7.5
- Fixed Issue #3 - It is now possible to configure location and names of output reports
- Fixed Issue #1 - Output reports now generate into target directories of each sub project rather than the parent project in a multi module project
- Fixed Issue #4 - Cucumber gems are now deleted when running the clean-lib task
- Fixed Issue #5 - Updated to Cucumber 0.10.0 and cuke4duke 0.4.3
- Fixed Issue #2 - Allowed cucumber tasks to be called from the parent project with separate parameterised tasks that can only be run on child projects
- Bug fixes
- First public release