Selenium vs XmlUnit+HttpClient for web REST API testing

I need to test web API functions in REST format. Currently using Selenium RC for functionally testing the website. And using XmlUnit and HttpClient to functionally test our REST API. But it seems life would be easier if we could really separate our functional testing code into all selenium. Particularly with Selenium 2.0’s WebDriver, it looks easier than ever to test XML responses using XPath.

My thoughts in the Pro XmlUnit+HttpClient camp:

  • allows easily testing with direct database calls or Spring beans
  • more easily allows testing JSON responses when/if we support that in the future
  • selenium was meant for web UI, not REST API testing

My thoughts in the Pro Selenium WebDriver camp:

  • separates out the functional testing all into standard selenium tests
  • easily test results by using our other selenium UI tests, further testing the UI
  • allows others than core developers to review functional API tests
  • maybe easier to use services like BrowserMob, which uses selenium tests, to load test API?
  • hopefully quicker functional tests with selenium framework

We’re using Spring 3 and hibernate. What’s best for functionally testing our API?

Another option might be to use REST Assured, a Java DSL for testing REST services. It allows you to write unit style tests with little boilerplate code for both XML and JSON. Additionally, it provides more advanced features like authentication, XSD / DTD validation, response codes, cookies, etc. More information is available at their usage page.

Disclaimer: REST Assured is an open source project initiated by a colleague of mine.