<p>My team is responsible for the development of an API for a large system that we also write. We need to provide example code so that other developers using our API can learn how to use it. We have been documenting the code using the xml document comments.
eg.</p>

<pre><code>/// &lt;summary&gt;Summary here&lt;/summary&gt;
/// &lt;example&gt;Here is an example  &lt;code&gt;example code here&lt;/code&gt; &lt;/example&gt;
public void SomeFunction() 
</code></pre>

<p>We then use Sandcastle and build the help files we need (chm and an online website).</p>

<p>It is quite embarrassing when the example code doesnt work, and this is usually because some functionality has changed or a simple error.</p>

<p>Has anyone ever done something like this, but also configured unit tests to run on the example code so that they are known to work during the build?</p>

Simple solution:
Make a small application in which you include all the sample code headers and then call their respective entry points
```
```
#include "samples/sampleA.h"

void main()
{
  SomeFunction();
}
```
```
then after you make a build run these little apps you need to be sure they ran ok.
But can you verify that the code ran ok without having someone have a slumber party with the NightlyBuild server?
Better Solution:
Log the output and have someone look at it in the morning.
Even Better Solution:
Log the output and grep it or something so no one has to look at it unless its broken.
Best Solution:
Find a suitable test framework, hopefully something with all the bells and whistles you can get so it can email people if its broken or something like that. In our case we avoid the bells and whistles instead we connected a
USB Police Siren
that goes off when something breaks It's quite exciting!