• Text Post
Cucumber-JVM 1.0.0
Today I am very excited to announce Cucumber-JVM 1.0.0.
Cucumber-JVM is a pure Java implementation of Cucumber, with native support for the most popular JVM languages: Java, Scala, Groovy, Clojure, Rhino, Jython and JRuby. Cucumber-JVM is the successor of Cuke4Duke, which was the Ruby implementation of Cucumber, running on JRuby. Cuke4Duke was a pain to use - it was hard to install and both slow and difficult to run.
Cucumber-JVM on the other hand is easy to install, and it’s fast and easy to run (thanks to its JUnit integration).
I will be giving an introduction to Cucumber-JVM at CukeUp! on April 4, and I am also working on documentation, but for now let me give you a quick glance of what you can do with it. We are going to create the following files:
. |-- build.xml (Optional) |-- pom.xml (Optional) `-- src |-- main | `-- java | `-- cucumber | `-- examples | `-- java | `-- helloworld | `-- Hello.java `-- test |-- java | `-- cucumber | `-- examples | `-- java | `-- helloworld | |-- HelloStepdefs.java | `-- RunCukesTest.java `-- resources `-- cucumber `-- examples `-- java `-- helloworld `-- helloworld.feature
Start by creating helloworld.feature
:
Feature: Hello World Scenario: Say hello Given I have a hello app with "Howdy" When I ask it to say hi Then it should answer with "Howdy World"
Now, create a pom.xml if you want to use Maven or a build.xml if you want to use Ant. This is all you need to download Cucumber-JVM and run your features.
Next, create RunCukesTest.java
which is used to run features from JUnit:
package cucumber.examples.java.helloworld; import cucumber.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @Cucumber.Options(format = {"pretty", "html:target/cucumber"}) public class RunCukesTest { }
We are passing some options to Cucumber, telling it to generate a HTML report as well.
When you run ant download runcukes
or mvn test
you will see all of your steps showing up as undefined. Cucumber-JVM will print some snippets to get you started. Let’s add those snippets to HelloStepdefs.java
and fill in the blanks:
package cucumber.examples.java.helloworld; import cucumber.annotation.en.Given; import cucumber.annotation.en.Then; import cucumber.annotation.en.When; import static org.junit.Assert.assertEquals; public class HelloStepdefs { private Hello hello; private String hi; @Given("^I have a hello app with \"([^\"]*)\"$") public void I_have_a_hello_app_with(String greeting) { hello = new Hello(greeting); } @When("^I ask it to say hi$") public void I_ask_it_to_say_hi() { hi = hello.sayHi(); } @Then("^it should answer with \"([^\"]*)\"$") public void it_should_answer_with(String expectedHi) { assertEquals(expectedHi, hi); } }
Finally we need an implementation of our Hello World system in Hello.java
:
package cucumber.examples.java.helloworld; public class Hello { private final String greeting; public Hello(String greeting) { this.greeting = greeting; } public String sayHi() { return greeting + " World"; } }
Run Ant or Maven again, and all is green. If you would rather do all of this in Scala, Groovy, Clojure, Rhino, Jython, JRuby - or even Ioke - that’s easy too. You will find more examples here.
Some other features of Cucumber-JVM:
- Multiple output formats: HTML, JSON, JUnit and more.
- DI support: PicoContainer, Guice, Spring, Weld and OpenEJB.
- Automatic conversion of step definition arguments.
- I18n support for over 40 spoken languages
- Grails and Play support on its way.
- IntelliJ support is on the way.
Take it for a spin and let us know what you think!
Notes
- jponge reblogged this from aslakhellesoy
- lastmodernist liked this
- haru012 reblogged this from aslakhellesoy
- aslakhellesoy posted this