Java – What unit test frameworks exist for Java

javascalaunit testing

I've used TestNG and JUnit. What other frameworks are out there? What makes them special and/or different from the rest?

Best Answer

Scala Specs gets my vote! :-)

Specs is a behavior-driven-development testing framework written in Scala. It can be used to write tests for Java and Scala. It was inspired by RSpec - a testing framework very popular in the Ruby world.


An example test written in Specs:

import org.specs._

object ElementSpecification extends Specification {
  "A UniformElement" should {
    "have a width equal to the passed value" in {
      val ele = elem('x', 2, 3)
      ele.width must be_==(2)
    }

    "have a height equal to the passed value" in {
      val ele = elem('x', 2, 3)
      ele.height must be_==(3)
    }

    "throw an IAE if passed a negative width" in {
      elem('x', 2, 3) must throwA(new IllegalArgumentException)
    }
  }
}

Impressive, isn't it? :-)

Related Topic