API documentation with executable examples

  • Authors:
  • Daniel Hoffman;Paul Strooper

  • Affiliations:
  • Department of Computer Science, University of Victoria, P.O. Box 3055 STN CSC, Victoria, BC, Canada V8W 3P6;School of Computer Science and Electrical Engineering, Software Verification Research Centre, The University of Queensland, Brisbane, Qld. 4072, Australia

  • Venue:
  • Journal of Systems and Software
  • Year:
  • 2003

Quantified Score

Hi-index 0.00

Visualization

Abstract

The rise of component-based software development has created an urgent need for effective application program interface (API) documentation. Experience has shown that it is hard to create precise and readable documentation. Prose documentation can provide a good overview but lacks precision. Formal methods offer precision but the resulting documentation is expensive to develop. Worse, few developers have the skill or inclination to read formal documentation.We present a pragmatic solution to the problem of API documentation. We augment the prose documentation with executable test cases, including expected outputs, and use the prose plus the test cases as the documentation. With appropriate tool support, the test cases are easy to develop and read. Such test cases constitute a completely formal, albeit partial, specification of input/output behavior. Equally important, consistency between code and documentation is demonstrated by runnig the test cases. This approach provides an attractive bridge between formal and informal documentation. We also present a tool that supports compact and readable test cases, and generation of test drivers and documentation, and illustrate the approach with detailed case studies.