Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning C# delegates into unit tests

In order to reduce code duplication I would like to generate unit tests programatically from various sources. One simple way I could think of was to generate a whole bunch of delegates from within a method that parses some configuration information and tags all those delegates with the [TestMethod] attribute which are then run by the visual studio test framework.

My motivation is to use as much of the visual studio's test reporting facilities as possible because I could write my own reporting layer for the tests by using some of C#'s reflection facilities but I rather not. My solution seems pretty elegant and simple but I can't get visual studio's test framework to understand what exactly I'm trying to do so does anyone know how to go about doing what I would like?

like image 831
David K. Avatar asked Nov 05 '22 17:11

David K.


1 Answers

You may want to consider Pex (and possibly Moles for legacy code) from Microsoft Research. Pex is a research project that automatically generates unit tests with high code coverage, and supposedly picks interesting input and outputs for the tests. I guess there's some intelligence there. :)

I have not personally used it, but I have heard from some peers that Pex and Moles is pretty interesting and has helped them out. May be worth a look.

Hope this helps!

like image 111
David Hoerster Avatar answered Nov 10 '22 05:11

David Hoerster