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
I have not done this myself but I've seen this mentioned in the Pragmatic Programmers books. If I'm not mistaken the book "Pragmatic Unit Testing in C# with Nunit" mentions that they did this for the book. It could be that they mentioned in one of their podcasts though.
They mentioned they had a continuous build server set up for their books. If I'm not mistaken they used latex or some other text based markup to write their books in and they had build steps for formatting the markup and building and unit testing code in the book.