Skip to content

Commit 1e813bf

Browse files
committed
Added some debug to the launcher to try to identify why the tests lock up after completion.
Updated the documentation to describe the new freatures and what tasks still need sorting. Updated the multiModule test project to use the new aproach.
1 parent 0ec12b2 commit 1e813bf

File tree

7 files changed

+80
-17
lines changed

7 files changed

+80
-17
lines changed

README.markdown

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@ xsbt-cucumber-plugin
33

44
An [sbt 0.12.x](https://github.com/harrah/xsbt/wiki) plugin for running [Cucumber](http://cukes.info) features.
55

6-
IMPORTANT: Release 0.5.0 onwards are a major update that switches from running the ruby version of cucumber (using JRuby) to running cucumber-jvm. This provides a significant improvement in speed and reliability. It also significantly changes the configuration options for the plugin. If you are using a version of this plugin before 0.5.0, please read below and update your project configurations to match the new options.
6+
### IMPORTANT NOTES ABOUT THIS RELEASE (0.7.0) ###
7+
It adds the ability to run cucumber as a standalone SBT task but also as a test runner within the standard 'test' task. To facilitate this, there has been one significant change that you should be aware of: the default location for feature files has changed from the src/test/features directory to the classpath. This is required as running as a test framework only has access to the test classpath. Features should therefore now live under src/test/resources. It is possible to change this back to another location by overriding the cucumberFeaturesLocation setting, but if you change this to anything other than the classpath then the 'test' task will not be able to find features.
78

9+
### EXPERIMENTAL RELEASE ###
10+
This is currently an experimental release of the ability to run cucumber as a standard SBT test framework. The basic mechanisms are in place, but currently the following are broken / do not work:
11+
12+
* When running the 'test' target, cucumber runs but then seems to lock up rather than return control back to SBT [Major]
13+
* Currently does not work with Scala 2.10.0-RC1 (I've only been testing against 2.9.2 projects and need to cross-build the integration project to allow it to work)
14+
* There is currently no support for 'test-only' and no way to just run features with specific names or tags
15+
* When running in a multi-project setup, the cucumbers for each project are run in parallel and the output is interleaved and thus unreadable.
16+
17+
This version is not published to any repository. You can build it locally using the SBT tasks: package and publish-local.
18+
19+
## Overview ##
820
Provides the ability to run Cucumber-jvm within the SBT environment. Originally based on the [cuke4duke-sbt-plugin](https://github.com/rubbish/cuke4duke-sbt-plugin) by rubbish and my original implementation for SBT 0.7.x. Specifics for this release:
921

1022
* Works with xsbt 0.12.0
1123
* Works with cucumber-jvm (version 1.0.9 for Scala 2.9.x and version 1.1.1 for Scala 2.10.0-RC1)
1224
* Allows projects compiled and running against Scala 2.9.1, 2.9.2 and 2.10.0-RC1
1325

14-
## Usage ##
15-
Install the plugin (see later). By default features files go in a 'src/test/features' directory. Step definitions go in 'src/test/scala'. Finally from the sbt console call the task:
26+
## Usage - Standalone Task ##
27+
Install the plugin (see later). By default features files go in the 'src/test/resources' directory. Step definitions go in 'src/test/scala'. Finally from the sbt console call the task:
1628

1729
cucumber
1830

@@ -29,8 +41,23 @@ would run features with a name matched to "User admin". Multiple arguments can b
2941
* arguments starting with @ or ~ will be passed to cucumber using the --tags flag
3042
* arguments starting with anything else will be passed to cucumber using the --name flag
3143

44+
## Usage - Test Framework ##
45+
Install the plugin and additional test framework integration (see later). Feature files MUST go in the 'src/test/resources' directory as only the classpath is visible to test frameworks. Step definitions go in 'src/test/scala'.
46+
47+
There must also be present somewhere in the test code the following class:
48+
49+
class CucumberSuite extends templemore.sbt.cucumber.RunCucumber
50+
51+
This is required to trigger cucumber to run (as SBT only runs tests that extends a specific base class or have a specific annotation). There MUST only be one instance of a class extending RunCucumber in the test code as we only want cucumber to be executed once! Finally from the sbt console call the task:
52+
53+
test
54+
55+
Note that none of the configuration options apply when running via a test framework. This is because the SBT test integration does not allow any access to these settings. Cucumber will be executed with pretty output to the console, searching the classpath from its root for features and executing all tests found in packages.
56+
57+
TODO: Support for test-only that runs cucumber just once but supporting tag and name arguments.
58+
3259
## Writing Features ##
33-
Features are written in text format and are placed in .feature files inside the 'src/test/features' directory. For more info on writing features please see the [Cucumber](http://cukes.info) website.
60+
Features are written in text format and are placed in .feature files inside the 'src/test/resources' directory. For more info on writing features please see the [Cucumber](http://cukes.info) website.
3461
For example:
3562

3663
Feature: Cucumber
@@ -43,7 +70,7 @@ For example:
4370
When I run the cucumber goal
4471
Then Cucumber is executed against my features and step definitions
4572

46-
The location of the features can be changed by overriding a plugin setting (see below).
73+
The location of the features can be changed by overriding a plugin setting (see below) - but only when using the cucumber task.
4774

4875
## Writing Step Defitions ##
4976
Step definitions can be written in Scala, using the Scala DSL. More information on this api can be obtained from the the [Cucumber](http://cukes.info) website.
@@ -91,6 +118,17 @@ To add the cucumber plugin settings to a basic project, just add the following t
91118

92119
The testProjects/testProject in the plugin source repository shows this configuration.
93120

121+
#### Running as a test framework ####
122+
If you wish to support cucumber running as a test framework (via the test task) then the following settings should be placed in the build.sbt file instead:
123+
124+
libraryDependencies ++= Seq(
125+
"templemore" %% "sbt-cucumber-integration" % "0.7.0" % "test"
126+
)
127+
128+
seq(cucumberSettingsWithTestPhaseIntegration : _*)
129+
130+
Note that cucumberSettingsWithTestPhaseIntegration replaces cucumberSettings in this case. The testProjects/testIntegrationProject in the plugin source repository showns this configuration.
131+
94132
### Full Configuration ###
95133
To add the cucumber plugin settings to a full configuration (often a multi-module) project, the best way is to implement a project/Build.scala file:
96134

@@ -108,11 +146,23 @@ To add the cucumber plugin settings to a full configuration (often a multi-modul
108146

109147
The testProjects/multiModuleTestProject in the plugin source repository shows this setup in a multi-module project.
110148

149+
#### Running as a test framework ####
150+
If you wish to support cucumber running as a test framework (via the test task) then the following settings should be placed in the build file instead:
151+
152+
val testIntegration = "templemore" %% "sbt-cucumber-integration" % "0.7.0" % "test"
153+
154+
lazy val myProject = Project ("my-project", file ("."),
155+
settings = Defaults.defaultSettings ++
156+
CucumberPlugin.cucumberSettingsWithTestPhaseIntegration ++
157+
Seq(libraryDependencies ++= Seq(testIntegration)))
158+
111159
## Customisation ##
112-
The plugin supports a number of customisations and settings. The following settings can be modified to change the behaviour of the plugin:
160+
The plugin supports a number of customisations and settings. Note that these setting customisations only apply to running using the standalone 'cucumber' task. Running cucumber as a test framework does not support any customisation options.
161+
162+
The following settings can be modified to change the behaviour of the plugin:
113163

114164
### Cucumber Settings ###
115-
* cucumberFeaturesDir - The location of the cucumber features directory within the projects. Defaults to a java.io.File of ./src/test/features
165+
* cucumberFeaturesLocation - The location of the cucumber features directory within the projects. Defaults to the String "classpath:". Can be set to a specific classpath location or a full file path
116166
* cucumberStepsBasePackage - The base package from which to search for files containing Steps. Defaults to an empty String (search all packages)
117167
* cucumberExtraOptions - Additional commandline options to pass to the cucumber command. Defaults to an empty List[String]
118168

@@ -150,7 +200,8 @@ Requests for features can be posted to the issues list or emailed to the author.
150200

151201
### 0.7.0 ###
152202

153-
TODO
203+
Significant refactor to support running cucumber via the standalone 'cucumber' task or integrated as test framework that can run as part of the standard SBT 'test' task.
204+
The default location for feature files is now on the classpath, requiring features to be placed in src/test/resources.
154205

155206
### 0.6.2 ###
156207
Upgrade to cucumber-jvm version 1.1.1 to allow compatibility with Scala 2.10.0-RC1 release.

integration/src/main/scala/templemore/sbt/cucumber/ReflectingCucumberLauncher.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class ReflectingCucumberLauncher(debug: (String) => Unit, error: (String) => Uni
2020
private def runCucumber(runtime: AnyRef) = try {
2121
val runtimeClass = runtime.getClass
2222
runtimeClass.getMethod("writeStepdefsJson").invoke(runtime)
23+
println("*** about to call run()...")
2324
runtimeClass.getMethod("run").invoke(runtime)
25+
println("*** run() complete, getting exit status...")
2426
runtimeClass.getMethod("exitStatus").invoke(runtime)
2527
} catch {
2628
case e: InvocationTargetException => {

testProjects/multiModuleTestProject/jar-project/src/test/scala/test/CucumberJarSteps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ class CucumberJarSteps extends ScalaDsl with EN with ShouldMatchers {
2121
whenCalled should be (true)
2222
}
2323
}
24+
25+
class CucumberSuite extends templemore.sbt.cucumber.RunCucumber
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sbt._
22
import Keys._
3-
import templemore.xsbt.cucumber.CucumberPlugin
3+
import templemore.sbt.cucumber.CucumberPlugin
44

55
object BuildSettings {
66
val buildOrganization = "templemore"
@@ -10,17 +10,23 @@ object BuildSettings {
1010
val buildSettings = Defaults.defaultSettings ++
1111
Seq (organization := buildOrganization,
1212
scalaVersion := buildScalaVersion,
13-
version := buildVersion) ++
14-
CucumberPlugin.cucumberSettings ++
15-
Seq (CucumberPlugin.cucumberHtmlReport := true,
16-
CucumberPlugin.cucumberPrettyReport := true)
13+
version := buildVersion)
14+
15+
// NOTE: If not worried about integration with the 'test' task then use:
16+
// CucumberPlugin.cucumberSettings instead of CucumberPlugin.cucumberSettingsWithTestPhaseIntegration
17+
val cucumberSettings = CucumberPlugin.cucumberSettingsWithTestPhaseIntegration ++
18+
Seq(CucumberPlugin.cucumberHtmlReport := true,
19+
CucumberPlugin.cucumberPrettyReport := true)
1720
}
1821

1922
object Dependencies {
2023

21-
val scalaTest = "org.scalatest" %% "scalatest" % "1.7.2" % "test"
24+
val scalaTest = "org.scalatest" %% "scalatest" % "1.7.2" % "test"
2225

23-
val testDeps = Seq(scalaTest)
26+
// NOTE: This dependency is only required when using 'test' task integration
27+
val testIntegration = "templemore" %% "sbt-cucumber-integration" % "0.7.0" % "test"
28+
29+
val testDeps = Seq(scalaTest, testIntegration)
2430
}
2531

2632
object TestProjectBuild extends Build {
@@ -32,8 +38,8 @@ object TestProjectBuild extends Build {
3238

3339

3440
lazy val jarProject = Project ("jar-project", file ("jar-project"),
35-
settings = buildSettings ++ Seq (libraryDependencies ++= testDeps))
41+
settings = buildSettings ++ cucumberSettings ++ Seq (libraryDependencies ++= testDeps))
3642

3743
lazy val warProject = Project ("war-project", file ("war-project"),
38-
settings = buildSettings ++ Seq (libraryDependencies ++= testDeps)) dependsOn (jarProject)
44+
settings = buildSettings ++ cucumberSettings ++ Seq (libraryDependencies ++= testDeps)) dependsOn (jarProject)
3945
}

testProjects/multiModuleTestProject/war-project/src/test/scala/test/CucumberWarSteps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ class CucumberWarSteps extends ScalaDsl with EN with ShouldMatchers {
2121
whenCalled should be (true)
2222
}
2323
}
24+
25+
class CucumberSuite extends templemore.sbt.cucumber.RunCucumber

0 commit comments

Comments
 (0)