Does anyone have an example of a cucumber project with sbt 0.13 and Scala 2.11?
cucumber-scala_2.11
and the sbt-cucumber-plugin" % "0.8.0"
(is that plugin up to date)?.feature
files go?Ok, I figured out a solution with the following caveat: I'm not using sbt.
We will write cucumber features and steps first. Then we will write a "Runner" class, that will be run by JUnit runner (which will be oblivious to the presence of cucumber)
Step 1. Depend only on one thing for writing cucumber features and steps!
libraryDependencies += "info.cukes" % "cucumber-scala_2.11" % "1.2.4"
Step 2: Now we depend on junit (for writing the runner of our tests) and cucumber-junit connection library that will allow us to tell JUni to run our cucumber tests:
libraryDependencies += "info.cukes" % "cucumber-junit" % "1.2.4"
libraryDependencies += "junit" % "junit" % "4.12"
Step 3: Write feature and steps definitions (they should be placed in the same folder in tests in my experience):
# My.feature
Feature: blah blah
....
// MySteps.scala
...
Step 4: Write our test runner:
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
@RunWith(classOf[Cucumber])
class RunTests extends {
}
Step 5: (optional) Integration with IntelliJ
a) Enable JUnit in IntelliJ. This will allow us to run our cucumber tests by running our junit runner. Beautiful!
File
Settings...
Plugins
Search for "JUnit" and make sure it's enabled
Now we can run our cucumber tests by simply right clicking on the .feature file and selecting Run!
b) Enable Cucumber for Scala IntelliJ plugin. (make sure Scala plugin is enabled). This enables IntelliJ to determine how to associate feature files with scala files. Without this your feature files will always be highlighted in yellow with an error undefined step reference
:
Files
Settings...
Plugins
Browse repositories...
search for "Cucumber for Scala"
Install Cucumber for Scala
plugin
Restart IntelliJ.
Now your feature files will be highlighted properly!
To add to @drozzy 's answer, specifically for sbt
:
add junit-interface
as a dependency in your sbt
project
"com.novocode" % "junit-interface" % "0.11" % Test
Write the test runner as @drozzy shows at step 4. Make sure you include the connection between JUnit and Cucumber:
@RunWith(classOf[Cucumber])
Once you do that, sbt test
will run your JUnit tests, and one of your "JUnit tests" will run your Cucumber tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With