Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful API Testbed with Swagger

I'm trying to develop an automated testing suite for a REST API. I've been told that Swagger would be the right tool to use to do this. The API is being developed using the Spring Framework.

I can't figure out how I would use Swagger to do this. From my understanding Swagger is used to create nice API documentation. I've looked at this Dreamfactory blog post and it looks like they've got some kind of in browser testing functionality, but I don't think its really a test suite.

I've also taken a look at ServiceStack( and cucumber) but since its another framework I don't think it would work.

This google group discussion didn't see to point anywhere in particular either.

So, does anyone know how to develop a RESTful API testbed using Swagger?

Thanks!

like image 402
illm Avatar asked Jun 22 '15 21:06

illm


2 Answers

As the other answers have mentioned, Swagger provides a way to define and document your API endpoints, methods, responses, errors, and more. It does not do any sort of automated testing out of the box.

There are a few tools that can read a Swagger definition to created automated tests, though:

  • Assertible is a tool where you can import your Swagger spec to automatically create tests and assertions for every endpoint and method. You can then set up monitoring, post deployment testing, and alerts. (Read the blog Testing an API using Swagger). It has a free plan with options to upgrade for more tests.
  • swagger-test is an NPM package, if you're looking for something to integrate with your code. I haven't personally used it, but it does look active and useful.
  • Dredd is another really cool open-source tool that will automate testing your Swagger spec against a live backend. This is also a CLI too, and it works with API Blueprint in addition to Swagger.

There's others as well, because Swagger provides a good common language for API developers there's some great tools that are written on top of it.

Another answer mentioned to check out the Commercial Tools page on swagger.io, which has some more hosted services (free and paid).

Full disclosure - I'm one of the co-founders of Assertible and would love to hear your feedback if you get a chance to use it.

like image 199
Cody Reichert Avatar answered Dec 10 '22 19:12

Cody Reichert


Swagger will let you nicely document your API, and will help you do manual, live tests with swagger-ui in that you can easily fill in arguments and see the responses through a web ui. Try the Swagger demo as an example of what I am referring to. http://petstore.swagger.io/

I have not tried this, but this might be of interest for more automated testing against Swagger definitions. https://github.com/Maks3w/SwaggerAssertions

like image 43
mmccaff Avatar answered Dec 10 '22 18:12

mmccaff