I recently downloaded Pex from Microsoft Research. Pex is a tool for finding test cases for you on basis of “looking” and “executing” your code. It is fully integrated in Visual Studio 2008 (c#). Pex explores your code by executing special Pex test method you have written. It basically comes down by making a “parameterized” version of a unit test you would normally make. This Pex test method will then call you unit under test (i.e. class method). Pex supplies values for the parameterized unit test . Meanwhile it will instruments your code do see which conditions it needs to check and which code paths it took during the exploration phase. After completing it adventure, it will generated unit test code. This unit test can then be executed by the Visual Studio Test Framework. For more information..... Before taking Pex for a spin , let's look at why a Pex was created.
Automated Unit testing is considered a good practice in software development. Nevertheless it is usually perceived as a burden by the developer. Besides the writing the actual code the programmer has to create and maintain this extra test code and of course exercising these unit tests. Depending on the code the amount of test cases , hence the unit test, can quickly grow. Also if you exercise the practice of “good” code coverage by your unit tests, you’ll discover that writing unit tests is hard work.
Sometimes the amount of test code supersedes the code under test. Much effort goes into creating the right amount of test cases so they cover every “corner” of you code. This code coverage criterion should result in a higher probability to find errors in your code. There several techniques that can help you establish these test cases. But these still leave writing the unit tests yourself.
Here's where pex steps in. Pex from Microsoft research can help achieve this coverage criterion by dynamically introspecting your code and based on that analysis can generate different test cases in the form “traditional” unit tests for the Visual Studio test framework.
I currently trying out some scenario's. Keep an eye for future posting...
Thanks for reading.