Search code examples
javascriptscalarestacceptance-testing

Which side should I choose to test REST API?


I developing REST API using Scala and Play Framework 2. Looks like right now is good time for writing acceptance specifications for this web service. There are two kinds of users for this API: web site and ipad app.

So, the question is which side should I choose to write acceptance specs?


To be much more concrete, by acceptance specifications I means such kind of tests:

"user" should {
  "be able to register with login, email and pass" in {
      ... // registration process here
   }
}

Here is my check lists

Server side (scala + specs2)

  • [+] easy to integrate into build process
  • [+] more familiar with scala
  • [-] easy to miss some browser specific details (for example CORS)

Client side (js + simple ajax or some testing framework)

  • [-] harder to automate (requires node.js, v8, phantomJS or something like that)
  • [-] more familiar with scala
  • [+] all browser details are taken in account
  • [+] eat your own dog food. Ability to use server side api as a client side programmer
  • [+] kind of examples for client side programmers

Solution

  • In my opinion the tests you called "Server side" could be unit tests, they should be fast and integrated into the build process, there you should test for API correctness, not for features like CORS, which belong to the client side.

    For the client side I recommend you to use Selenium IDE, it's a browser plugin that lets you record action and assert on what happens on the page, letting you replay all the actions later on, way faster than a human could do.

    I don't have experience in integrating that into a build workflow though, so if you need to have also this into your build process I suggest you to evaluate CasperJS, it has a wonderful documentation and useful testing features.

    If you just need acceptance tests I would definitely go on the frontend.