moznion's tech blog

moznion's technical memo

Docuss - A library to test with describing document for controller layer

I released a library "Docuss" for Java (this library requires Java 8 or later).
It is available in maven central.

maven central

This library works as below:

  • This library provides an inspection method to test the HTTP response. This library sends an HTTP request to target URI and it hands over the response to the inspector.
  • When test is passed, this library outputs the contents of the HTTP request and response *1 as any format by arbitrary method.

In short, this library provides a function to test HTTP request and response with describing their contents.
It is similar to autodoc, however docuss is more minimal (or cheaper?) than that.

Fundamental information and usage are written in the README and javadoc, the points that worked out are below;

  • Format of output is controllable
  • Method to output is controllable
  • It doesn't depend on any concrete HTTP client implementation

Format of output is controllable

This library can specify the format of output of documents.
It is easy to do that; you can specify the output format by writing formatter generator which outputs the formatter to convert contents of request and response to arbitrary format. Formatter generator must be implemented DocussFormatterGenerator interface.

Default, this library provides a formatter generator that generates YAML formatter.

Method to output is controllable

This library can specify the destination of the output. The way is just like formats’ one; you can specify the method to output by implementing the interface DocussPresenter.

Default, this library provides two presenters. One is a presenter to output to STDIN, another is a presenter to output to file with appending.

It doesn’t depend on any concrete HTTP client implementation

This library doesn’t depend on any concrete HTTP client implementation so if you want to use specific HTTP client, you can implement DocussHttpClient interface. Basically, the implementation of this interface bears the responsibility to implement the core of functions.

Default, this library supports the simple HTTP client layer implementation which is using Apache httpclient.

Conclusion

I think the way that outputs document from test code is right and natural. I want library to satisfy such function so implemented this.
I usually get out of breath when finished writing the production code and test code so it is difficult for me to write the document.
Even if it is in such a situation, we should write documents firmly so I think such library to support to write documents is necessary.

Enjoy.

*1:in this library, these are called "document"