Presentation
specs2 is a library for writing executable software specifications.
With
specs2 you can write software specifications for one class (
unit specifications) or a full system (
acceptance specifications):
import org.specs2.mutable._
class HelloWorldSpec extends Specification {
"The 'Hello world' string" should {
"contain 11 characters" in {
"Hello world" must have size(11)
}
"start with 'Hello'" in {
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
"Hello world" must endWith("world")
}
}
}
import org.specs2._
class HelloWorldSpec extends Specification { def is =
"This is a specification to check the 'Hello world' string" ^
p^
"The 'Hello world' string should" ^
"contain 11 characters" ! e1^
"start with 'Hello'" ! e2^
"end with 'world'" ! e3^
end
def e1 = "Hello world" must have size(11)
def e2 = "Hello world" must startWith("Hello")
def e3 = "Hello world" must endWith("world")
}
Features
The features of
specs2 are:

Concurrent execution of examples by default

Data tables

AutoExamples, where the source code is extracted to describe the example

A rich library of matchers

Easy to create and compose

Usable with
must
and
should

Returning "functional" results or throwing exceptions

Reusable outside of specs2 (in
JUnit tests for example)

Forms for writing
Fitnesse-like specifications (with Markdown markup)

Html reporting to create documentation for acceptance tests, to create a User Guide,...

Integration with
sbt and JUnit tools (maven, IDEs,...)
Dependencies
The
specs2 jar is available with both sbt and maven
libraryDependencies ++= Seq(
"org.specs2" %% "specs2" % "${SPECS2_VERSION}" % "test"
// with Scala 2.8.x (specs2 1.5 is the latest version for scala 2.8.x)
// "org.specs2" %% "specs2" % "1.5" % "test",
// "org.specs2" %% "specs2-scalaz-core" % "5.1-SNAPSHOT" % "test"
)
// Read here for optional dependencies:
// http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html#Dependencies
resolvers ++= Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
"releases" at "http://oss.sonatype.org/content/repositories/releases")
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_2.9.2</artifactId>
<version>${SPECS2_VERSION}</version>
<scope>test</scope>
</dependency>
<!--
with Scala 2.8.1, change the dependency to:
<artifactId>specs2_2.8.1</artifactId>
<version>1.5</version>
-->
<!--
Read here for optional dependencies:
http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html#Dependencies
-->
<repository>
<id>oss.sonatype.org</id>
<name>releases</name>
<url>http://oss.sonatype.org/content/repositories/releases</url>
</repository>
<repository>
<id>oss.sonatype.org</id>
<name>snapshots</name>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>central</id>
<name>Maven repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>ObjectWeb</id>
<name>ObjectWeb repository</name>
<url>http://maven.ow2.org/maven2</url>
</repository>
Downloads
You can download the project here