ScalaTest
Helps creating feature tests for Unfiltered apps with scalatest.
Usage
Here is a test written using this support.
sourceclass ExampleFeature extends AnyFeatureSpec with unfiltered.scalatest.jetty.Served
with unfiltered.scalatest.Hosted
with GivenWhenThen with Matchers {
def setup = {
_.plan(new App)
}
Feature("rest app") {
Scenario("should validate integers") {
Given("an invalid int and a valid palindrome as parameters")
val params = Map("int" -> "x", "palindrome" -> "twistsiwt")
When("parameters are posted")
val response = httpx(req(host <<? params))
Then("status is BAD Request")
response.code should be(400)
And("""body includes "x is not an integer" """)
response.as_string should include("x is not an integer")
}
Scenario("should validate palindrome") {
Given("a valid int and an invalid palindrome as parameters")
val params = Map("int" -> "1", "palindrome" -> "sweets")
When("parameters are posted")
val response = httpx(req(host <<? params))
Then("status is BAD Request")
response.code should be(400)
And("""body includes "sweets is not a palindrome" """)
response.as_string should include("sweets is not a palindrome")
}
}
}
Limitations
Only Feature type scalatests are supported.
The source code for this page can be found here.