Chapter 8. Testing

 

This chapter covers

  • Integration testing with Specs2
  • Unit testing with Specs2
  • Testing with ScalaTest

By now, you’ve had a thorough introduction to the basic features of Scalatra. As good test-first developers, we feel a little guilty about waiting until now to introduce testing, but here we are.

Scalatra comes with a test DSL to simplify testing your application. The DSL follows the Scalatra philosophy of not being particularly opinionated. It works with both major Scala test frameworks, ScalaTest and Specs2. It’s suited to both integration and unit testing. And if it doesn’t fully suit your needs, it’s easy to pull out the pieces that do. It’s time to write your first test.

8.1. Integration testing with Specs2

Scalatra is built on the Java Servlet API. This design permits Scalatra to sit atop servers like Jetty and Tomcat, the most mature servers on the JVM. It also complicates testing for a few reasons:

8.2. Unit testing with Specs2

8.3. Testing with ScalaTest

8.4. Summary