The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Cucumber-JVM 1.0.0

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Aslak Hellesøy

Posts: 29
Nickname: aslak
Registered: Mar, 2005

Aslak Hellesoy is a senior developer for ThoughtWorks, Inc.
Cucumber-JVM 1.0.0 Posted: Mar 27, 2012 11:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Aslak Hellesøy.
Original Post: Cucumber-JVM 1.0.0
Feed Title: Aslak Hellesøy's uncommon sense
Feed URL: http://aslakhellesoy.com/rss
Feed Description: Ruby-related blog posts from Aslak Hellesøy
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Aslak Hellesøy
Latest Posts From Aslak Hellesøy's uncommon sense

Advertisement

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!

Read: Cucumber-JVM 1.0.0

Topic: On Community Funding of Open Source Previous Topic   Next Topic Topic: net-http-persistent 2.6

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use