Code generation for unit testing
There exists a project at Microsoft which generate unit tests based of source code. The name of this interesting project is Pex.
At the first time when I heard about this project I was skeptical.
- Where’s the value of generated tests?
- Doesn’t it break the “test first” approach?
After I saw this screencast from the PDC 2008, I could find the answers for me:
There is a value: It is often tedious to write all the unit tests with the extreme values which could pass to the method. For this tedious work it’s nice that you could generate all this “technical” unit tests. For this reason I would create an assembly where I would generate all this unit tests and separate them from the other unit tests, which I wrote by hand (and with the “test first” approach, like TDD).
The answer for the second question if it brakes the “test first” approach, is yes. But it isn’t a bad thing by nature. The generated tests are more technical stuff and they don’t serve as examples or specification.