specs2
Software Specifications for Scala

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 = s2""" This is a specification to check the 'Hello world' string The 'Hello world' string should contain 11 characters $e1 start with 'Hello' $e2 end with 'world' $e3 """ 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
ScalaCheck properties
Mocks with Mockito
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
Snippets for documenting APIs with always up-to-date code
Integration with sbt and JUnit tools (maven, IDEs,...)

Dependencies

The specs2 jar is available with both sbt and maven
libraryDependencies ++= Seq( "org.specs2" %% "specs2" % "2.3.13" % "test" // with Scala 2.9.3 (specs2 1.12.4.1 is the latest version for scala 2.9.3) // "org.specs2" %% "specs2" % "1.12.4.1" % "test", ) scalacOptions in Test ++= Seq("-Yrangepos") // Read here for optional dependencies: // http://etorreborre.github.io/specs2/guide/org.specs2.guide.Runners.html#Dependencies resolvers ++= Seq("snapshots", "releases").map(Resolver.sonatypeRepo)
<dependency> <groupId>org.specs2</groupId> <artifactId>specs2_2.10</artifactId> <version>2.3.13</version> <scope>test</scope> </dependency> <!-- with Scala 2.9.3, change the dependency to: <artifactId>specs2_2.9.3</artifactId> <version>1.12.4.1</version> --> <!-- Read here for optional dependencies: http://etorreborre.github.io/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>

Downloads

You can download the project here
VersionFiles
Snapshot binaries (specs2 jar, scalaz core jar, scalaz concurrent jar)
project (zip, tar)
Released binaries (specs2 jar, scalaz core jar, scalaz concurrent jar)
project (zip, tar)

You can also clone the project with Git by running:

$ git clone git://github.com/etorreborre/specs2