Using Spring REST Docs with automated tests

 

Spring REST docs provide a lot of features and flexibility to generate documentation for your REST APIs. One of the powers of REST docs is its ability to generate the documentation based on the unit tests which ensure that documentation is accurate, concise, and well-structured.

To enable the Spring REST Docs support, add spring-restdocs-mockmvc as an additional dependency in your application. 


Spring REST Docs use the test cases to generate accurate and updated documentation for the REST API.

If all tests pass with no issue, it will generate a sub-folder under the target/generated-snippets with a name matching the argument passed to the document method (in our case it is itShouldReturnThreeCustomers). There will be several .adoc files.

One of the limitations with the AsciiDoc doc is that it is unable to render in the browser. So AsciiDoc need to be converted into a browser-friendly format like HTML. To convert our documentation into HTML format, must be use the AsciiDoctor maven plugin.

To make sure generated .adoc snippets and AsciiDoctor Maven plugin working together to generate the documentation, we need to glue together the generated .adoc files. We need to create a new file index.adoc under src/main/asciidoc directory.



Go to source code

Comments

Popular posts from this blog

Debug Java Stream in Intellij Idea

Creating Efficient Docker Images with Spring Boot 2.3

CRUD Goes Even Easier With JPABuddy