Skip navigation.

Testing Code-Generated Code with NUnit, Temporary Files, Voodoo, Rubber Bands and Reflection

Testing Code-Generated Code with NUnit, Temporary Files, Voodoo, Rubber Bands and Reflection

NUnit | test driven development
We're into Unit Testing here and getting more so every day. We also do a lot of code generation as well, and struggled with how to test that the code generation works from end to end. [..] These [generated] objects should compile, have the correct attributes, be create-able at runtime, and serialize correctly.

Here's how we run CodeSmith in the NUnit tests to generate into temporary .g.cs files. The ".g.cs" extension is our own invention, allowing us to keep track of what's generated and what's written by hand.

Author: Scott Hanselman
Published: January 1, 2005