DEV Community

Discussion on: Testing an API Against its Documentation

Collapse
 
albertofdzm profile image
Alberto Fernandez Medina

Thanks for your comment!

I think that DDD could be a good way to design APIs before beign developed and ensure they works as the designs says. That is one of the problems in my actual job. Backend designs the API Docs for new functionalities and all the teams discuss them and request changes and additions but there are some times that the development doesn't fullfil the designs or the designs doesn't gets updated. This would solve those problems.

Sorry for the long comment.

Collapse
 
honzajavorek profile image
Honza Javorek

Dredd is more of a RDD tool (tom.preston-werner.com/2010/08/23/...), it won't completely replace all your unit tests. But otherwise it exists to solve exactly the problem you described. It makes sure the docs users are presented with are always correct, and that the API is always correct according to the design.

Thread Thread
 
albertofdzm profile image
Alberto Fernandez Medina

Nice article!

I don't think RDD would be a good practice in this case, as the author says:

By restricting your design documentation to a single file that is intended to be read as an introduction to your software

It may be overwhelming to have a README with the whole API specification, what if the user only want to read only an introduction to the API or some small examples, maybe read the contribution section or some other info that readme files should include.

It's true that the more documents you have the worst you will maintain them updated, but in my opinion, is better if you have a README file that refers to your API docs and offers some friendly introduction and examples, maybe a FAQ and some project info.

Thread Thread
 
honzajavorek profile image
Honza Javorek

The API description document (API Blueprint, Swagger, OpenAPI) usually describes the API in form of some expected happy scenarios. Usually, it doesn't contain examples for all the corner cases. In this sense, it is something like README for a software project. It helps user to understand how to use the API, but it doesn't replace the reference book. For that reason, if you test your API against your API description by Dredd, you get very very very useful thing - an assurance that what users read in the docs is exactly how the API works. But you don't get all the negative scenarios and all the corner cases, so you still need to add some unit/integration tests. That's why I think this is more of a RDD than DDD, but anyway, this is pretty much bike shedding :D

I had a talk on this topic on PyCon SK, maybe I'm clearer in expressing my thoughs there - youtube.com/watch?v=mGUul6NbYw4&li...

I completely agree an actual README should not be equal to an API description.

And by the way, thanks for a great article. We should definitely link it from the Dredd docs! It's better than our own tutorials. It's amazing to see when people find Dredd so useful they even write articles about it.

Thread Thread
 
albertofdzm profile image
Alberto Fernandez Medina

Thank you very much!

Haha, I didn't know you were one of the main contributors to Dredd! Thanks a lot for work on tools like this!

I saw part of the presentation, I didn't know such tools like doctests exists! This is amazing.

Thanks for your comments and contributions.