Tuesday, 22 July 2008

Starting with Pex (Program Exploration)

Hello,

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.

Best regards,


Alexander

2 comments:

Anonymous said...

Huh?

Is this for regression tests on legacy code or something, or do Microsoft just not get it?

If your code isn't covered by a test then you can safely delete the code - it is not being used.

Or do some people still not get the whole point of tests?

anowak said...

Hello,

The scenario you state is very plausible. I think a tool like pex can give you a big headstart compared to doing every thing manual.

In a TDD scenario I can understand your remark. In that context I would like to point you the following page (http://submissions.agile2008.org/node/2766 ).


On the Agile 2008 conference the Pex team (Jonathan de Halleux, Nikolai Tillmann) will elaborate how you can use Pex in a TDD track (Exploratory Test Driven Development: Red,Yellow, Green, Refactor).


Best regards,

Alexander