4

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?

Mosam Mehta
  • 1,658
  • 6
  • 25
  • 34
at.
  • 50,922
  • 104
  • 292
  • 461

3 Answers3

6

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.

matsev
  • 32,104
  • 16
  • 121
  • 156
2

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.

Tom Mayfield
  • 6,235
  • 2
  • 32
  • 43
Bill
  • 429
  • 2
  • 4
  • I think your answer could benefit if you briefly explain why you feel Selenium is a poor choice for this scenario, I'm also curious since I'm considering trying it! Thanks – GrahamMc May 24 '13 at 17:27
-1

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • hmmm... I guess testing an API is in between unit and functional... good point. – at. Dec 07 '10 at 23:29
  • 1
    I'd call it integration testing rather than unit testing. Assuming the code behind the API is unit tested, this kind of tests would mostly verify that the unit test assumptions are correct and thus that the different units can be _integrated_ properly. – David Pärsson Sep 27 '12 at 14:06
  • A functional and unit test are not mutually exclusive. The lowest testable function possible, could very well be the entire functionality. Even though a web-service is designed to be consumed by another system it's still a website, and a test that encompasses the complete functionality of it would be a Functional test. None the less, using Selenium to test non-Javascript/static websites is probably an overkill. As Confucius said "Don't use cannon to kill mosquito." – Manatax Apr 10 '13 at 06:36