JDoctest is an implementation of Python's doctest for Java, based on the ideas in doctestj (http://code.google.com/p/doctestj/) and Rhino (http://blog.norrisboyd.com/2008/03/doctest-in-rhino.html). Unlike doctestj, JDoctest is a javadoc Taglet, rather than a Doclet. It doesn't replace the standard javadoc, it just adds a new @doc.test tag. We also use a multiline format similar to Python's doctest (based on Rhino's implementation) rather than insist on a single evaluated expression, as doctestj does. See the compiled javadoc for net.cscott.jdoctest.JDoctest for further examples of use. To build: * Copy sample.build.properties to build.properties and edit it to properly reflect that path to your JDK. (We need to use the tools.jar file from the JDK, so we need to know where to find it.) * Run 'ant javadoc', which will build the source code and then run its doctests. * One failure is to be expected as the tests are run; it is included to show the results of a failing test in the output javadoc. To install: * Move the generated jdoctest-*.jar as well as lib/rhino*/js.jar to a directory in your project. If your project uses a pre-1.5 JDK, use lib/rhino*/js-14.jar instead of js.jar. Below, we will assume that you've placed both these files in lib/jdoctest in your project. To invoke from the command line: javadoc -taglet net.cscott.jdoctest.JDoctest \ -tagletpath lib/jdoctest/jdoctest.jar:lib/jdoctest/js.jar:bin \ -J-ea \ We're assuming that your source code has been compiled into 'bin'. Note that your compiled .class files must be included on the tagletpath so that we can run the doctests. Use js-14.jar instead of js.jar if your project uses a pre-1.5 JDK. Note that you need to use the -J-ea option if you want assertions to be enabled during the evaluation of the doctests. You can use -J-ea:... to only enable assertions in your code (not in the entire javadoc tool). Ant rule: As before, replace 'bin' with the appropriate path to your compiled project classes, and use js-14.jar instead of js.jar if your project uses a pre-1.5 JDK. The -J-ea option ensures assertions are enabled in your code when doctests are evaluated. You may want to add css rules to make the output prettier. JDoctest has hooks to allow the use of google-code-prettify: http://code.google.com/p/google-code-prettify/ which will do syntax highlighting on the client side. The build.xml file for JDoctest shows how this might be hooked up. The files in src/doc-test should be copied to the top-level source directory of your project. Note that javadoc's directory structure for the generated documentation makes it tedious to link to the top-level doc-files directory from the generated documentation, but we add a