Automating code testing
Chapter 9 covered best practices for creating and maintaining functioning code examples and touched on the importance of testing to ensure this. As developers, you likely already have a reasonable idea of the general options available for testing code, but how do you make this work with code examples in documentation? And how do you automate it?
Keep the code separate from documentation and test it mostly as a self-contained application. It may not surprise you that there are advantages, disadvantages, and tools to help while doing this. Luckily, for the most part, it uses tools already familiar to developers.
First, you need to use a markup language or documentation rendering tool that handles the use of file inclusion and, ideally, one with extra features for including code files.
For example, one potentially useful feature is only to import certain lines from a file so that you can hide boilerplate code not useful for an example but needed to test...