4
votes

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?

3

3 Answers

6
votes

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.

2
votes

If you want to do real functional testing on rest API's, then I can recommend Fitnesse with this fixture: https://github.com/smartrics/RestFixture

Selenium is just a poor choice for this kind of thing.

As for performance testing you can knock up rest API tests in Jmeter in a matter of minutes, no need to pay a 3rd party.

-1
votes

Testing an API does not sound like functional testing but more like unit-testing. So I'd go for XmlUnit+HttpClient