Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature-level behavior testing tools for Java/Scala

Tags:

java

scala

bdd

Is there a Java or Scala equivalent to Cucumber/SpecFlow? One possibility is using Cucumber with JRuby; any others?

like image 850
Alexey Romanov Avatar asked Jun 08 '10 20:06

Alexey Romanov


People also ask

What is cucumber for Scala?

Cucumber is a tool that supports Behaviour-Driven Development (BDD) - a software development process that aims to enhance software quality and reduce maintenance costs; ScalaTest: A testing tool in the Scala ecosystem. You can test Scala, Scala. js (JavaScript), and Java code with this tool.

Which of the following is BDD tool?

SpecFlow is a BDD Tool for .

What is ScalaTest used for?

ScalaTest is one of the most popular, complete and easy-to-use testing frameworks in the Scala ecosystem. Where ScalaTest differs from other testing tools is its ability to support a number of different testing styles such as XUnit and BDD out of the box.


1 Answers

Take a look at ScalaTest with Feature Spec. Sample feature spec from the ScalaTest website:

import org.scalatest.FeatureSpec
import org.scalatest.GivenWhenThen
import scala.collection.mutable.Stack

class ExampleSpec extends FeatureSpec with GivenWhenThen {

  feature("The user can pop an element off the top of the stack") {

    info("As a programmer")
    info("I want to be able to pop items off the stack")
    info("So that I can get them in last-in-first-out order")

    scenario("pop is invoked on a non-empty stack") {

      given("a non-empty stack")
      val stack = new Stack[Int]
      stack.push(1)
      stack.push(2)
      val oldSize = stack.size

      when("when pop is invoked on the stack")
      val result = stack.pop()

      then("the most recently pushed element should be returned")
      assert(result === 2)

      and("the stack should have one less item than before")
      assert(stack.size === oldSize - 1)
    }

    scenario("pop is invoked on an empty stack") {

      given("an empty stack")
      val emptyStack = new Stack[String]

      when("when pop is invoked on the stack")
      then("NoSuchElementException should be thrown")
      intercept[NoSuchElementException] {
        emptyStack.pop()
      }

      and("the stack should still be empty")
      assert(emptyStack.isEmpty)
    }
  }
}
like image 111
Abhinav Sarkar Avatar answered Oct 05 '22 22:10

Abhinav Sarkar