Skip to content

Instantly share code, notes, and snippets.

@schauder
Created August 30, 2011 18:57
Show Gist options
  • Save schauder/1181705 to your computer and use it in GitHub Desktop.
Save schauder/1181705 to your computer and use it in GitHub Desktop.
A simple collection of ScalaTest examples
package de.schauderhaft.testen
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.BeforeAndAfterEach
@RunWith(classOf[JUnitRunner])
class DemonstrationTest extends FunSuite with ShouldMatchers {
def setup = ("einen Wert", 23)
test("Dies ist ein Test der Demonstrieren soll, wie ein ScalaTest test funktioniert") {
23 should be > (12)
}
test("die Klasse unter test muss dies können") {
val l = List(12, 23, 45)
l should not be ('empty)
}
test("that this piece throws an exception") {
(intercept[IllegalArgumentException] {
throw new IllegalArgumentException("wrong")
}).getMessage() should include("on")
}
test("test mit setup") {
val (text, length) = setup
text.length should be <= length
}
val testValues = List(("word", 4), ("otherword", 9))
for ((in, l) <- testValues) {
test("%s hat Länge %d".format(in, l)) {
in should have length (l)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment