Testing with Pex

Some time ago I read about (might be on Dot­NetRocks) a lit­tle gem com­ing out of Microsoft’s research lab called Pex, which is a frame­work for doing auto­mat­ed White Box Test­ing in .Net. It’s still in its ear­ly days (despite hav­ing been around for more than 2 years now) but packs a bag of poten­tial judg­ing by what I’ve seen of the demo mate­ri­als and been able to use myself!

In short, Pex is able to ana­lyze your meth­ods and work out the bound­ary con­di­tions, etc. and derive a series of tests that can be used to test your method with as high a cov­er­age as pos­si­ble. The down­load pack­age also includes a light­weight frame­work for test stubs and detours (which basi­cal­ly allows you to replace any .Net method with your own del­e­gate) called Stubs and Moles. It also comes with the abil­i­ty to auto­mat­i­cal­ly gen­er­ate test project for you in MSTest and NUnit though I haven’t test­ed out the NUnit gen­er­a­tion as it didn’t sup­port NUnit gen­er­a­tion the last time I played around it.

I won’t go into detail on how to use it as there are a ton of doc­u­men­ta­tion and demo mate­r­i­al on its site and I have bare­ly scratched the sur­face myself, but do check it out if you haven’t done so already!