Quick introduction to Pex
For business use Pex requires MSDN Library subscription. For academic use it is free right now. You can download Pex and Moles from Pex and Moles homepage.
Pex generates unit tests to test your code on the fly. It analyzes paths in your code and checks for different constraints and tries different parameters with tests to break your code. Parameter values are not randomly generated but meaningfully selected. This means that Pex is not about flooding and finding bugs randomly. After code analysis and testing Pex shows you results in Visual Studio IDE.
Now let’s try to do something simple that illustrates how Pex works.
Primitive test class
Let’s create new Class Library project using Visual Studio and let’s create there class called calculate. Here is my class.
public class Calculate
{
public static decimal Speed(decimal s, decimal t)
{
return s / t;
}
}
If you look at this class you can see that method Speed() is easy to crash – just give zero as value to argument t. Now let’s see what Pex thinks about our class.
Analyzing code with Pex
To run Pex on our code we have to right click on project and select Run Pex from context menu.
Now you are asked for test framework.
I selected nUnit but you can find also other frameworks there like Visual Studio tests and xUnit.
After clicking OK Pex starts analyzing and testing your code. It takes a little time so we have to wait a little bit.
Results
Pex shows us analysis results in two windows: Pex Explorer and Pex Exploration Results. Pex Explorer is good if we have more classes and it we want to navigate between them and test results. Pex Explorer is very similar to windows we have seen when running tests on our code.
Pex Exploration Results window shows us Pex results in more detail.
If we click on some line the details pane is opened that gives us better overview about what Pex did in this point.
In details windows we can also see test that Pex generated if we open details section.
As we can see then Pex discovered one more problematic situation – our code is not safe against overflows. In similar manner Pex is able to analyze more complex methods and gives us very good hints about weak sides of our code.
Conclusion
Pex is interesting tool that helps developers on analyzing code and generating parameterized unit tests. Pex is not about replacing tests or making them less important. Pex is about providing additional value to developers who are interested in their code quality and unit tests. Tests will never go away and Pex is here to help us find more tests we need to have to improve our code quality. Also you may consider Pex as helping tool that helps us on generating tests we want to add to our test libraries.
Cool feature, but I like other unit tests platforms like NUnit, MSBuild
Thanks for comment, Slava! I have to be more specific and say that Pex is not unit testing framework but complementary tool that helps you create unit tests for what ever unit test framework you are using.
Generating tests with Pex is optional. You can use like here – just to see if there are problems in your code that must be handled. You can write tests manually that check if these problems are there or not. Pex is just advising you.
763020 752617This internet internet site is my breathing in, genuinely very good layout and perfect content material . 951012
82740 423220Ill create a hyperlink to the internet page about my individual weblog. 128184
622036 871198Just wanna remark that you have a extremely good web site , I like the layout it truly stands out. 244585
683366 852769You got a very exceptional web site, Glad I noticed it through yahoo. 256448
17558 852320You can surely see your skills in the function you write. The world hopes for far more passionate writers like you who arent afraid to say how they believe. At all times follow your heart 865645
660325 526675Wow, cool post. Id like to write like this too – taking time and real effort to make a good article but I procrastinate too a lot and never appear to get started. Thanks though. 169450
814757 129801Some genuinely rattling work on behalf with the owner of this site , utterly excellent content material . 340495
525290 903987There is noticeably a bundle to know about this. I assume you produced certain good points in features also. 35181
656613 934183I truly appreciated this amazing weblog. Make confident you maintain up the good work. All of the best !!!! 820591
397394 459950You made some decent points there. I looked on the internet for the dilemma and discovered most individuals will go coupled with along along with your internet site. 471660
49716 896637There is noticeably a bundle comprehend this. I suppose you produced specific nice points in functions also. 447049
681792 150115This sort of considering develop change in an individuals llife, building our Chicago Pounds reduction going on a diet model are a wide actions toward making the fact goal in mind. lose weight 264688
190211 799540An very fascinating read, I may possibly possibly not agree completely, but you do make some extremely valid points. 217509
58637 316808This really is a exceptional blog, would you be involved in performing an interview about just how you created it? If so e-mail me! 8150
723703 576570There is noticeably plenty of cash to realize about this. I suppose you produced specific nice points in functions also. 252585
777711 443017BTW, and I hope we do not drag this too long, but care to remind us just what kind of weapons were being used on Kurds by Saddams army? To the tune of hundreds of thousands of dead Speak about re-written history 724915
467749 694102quite good publish, i undoubtedly love this web web site, carry on it 568213
32290 342590Having read this I thought it was quite informative. I appreciate you taking the time and effort to put this post together. I once again find myself spending way to significantly time both reading and commenting. But so what, it was nonetheless worth it! 190296
167482 570898I feel 1 of your advertisements triggered my internet browser to resize, you may want to put that on your blacklist. 603521
586073 862343I was just seeking this information for a while. After 6 hours of continuous Googleing, at last I got it in your web site. 964255
18115 177043Disgrace on the seek Google for not positioning this submit upper! Come on over and consult with my web site. 776251
839350 945513Glad to be one of several visitants on this incredible internet web site : D. 29673
288440 97921Was koche ich heute – diese Frage stellen sich tag fuer tag viele Menschen. Und wir haben tag fuer tag die perfeckte Antwort darauf! Besuchen Sie uns auf unserer Webseite und lassen Sie sich von uns beraten . Wir freuen uns auf Sie! 956195
748903 903868Amaze! Thank you! I constantly wished to produce in my internet web site a thing like that. Can I take element with the publish to my weblog? 911362
514055 937052Your talent is actually appreciated!! Thank you. You saved me a great deal of frustration. I switched from Joomla to Drupal to the WordPress platform and Ive fully embraced WordPress. Its so much easier and easier to tweak. Anyway, thanks once more. Awesome domain! 970340
514150 883899Hi, you used to write outstanding posts, but the last several posts have been kinda boring I miss your fantastic posts. Past couple of posts are just slightly bit out of track! 678926
3301 453312I agree with most of your points, but several want to be discussed further, I will hold a small speak with my partners and possibly I will appear for you some suggestion soon. 104333
538665 841049An intriguing discussion will probably be worth comment. I believe which you merely write considerably a lot more about this subject, it may become a taboo subject but normally consumers are inadequate to communicate in on such topics. To an additional. Cheers 93343
306276 145118Ich kenne einige Leute, die aus Kanadakommen. Eines Tages werde ich auch dorthin reisen Lg Daniela 599329
136953 344444Trop excitant de mater des femmes lesbiennes en train de se doigter la chatte pour se faire jouir. En plus sur cette bonne petite vid o porno hard de lesb X les deux jeunes lesbienne sont trop excitantes et super sexy. Des pures beaut de la nature avec des courbes parfaites, les filles c est quand v 439487
815598 373638I like you blog (dsol, je suis francais, je parle mal anglais) 981188
709772 957769Quite good style and style and great topic matter, extremely small else we want : D. 53112
984942 605729Some genuinely rattling function on behalf of the owner of this internet site , utterly wonderful content material . 809984
392519 642346You must participate in a contest for among the very best blogs on the internet. I will recommend this site! 700250
58603 113094Respect to site author , some very good selective data . 880328
894741 604169I gotta bookmark this web site it seems very beneficial . 904826
318409 640920You appear to be quite skilled in the way you write.::~ 947027
217711 646530This really is the proper weblog for anybody who hopes to learn about this topic. You know a complete lot its almost tough to argue along (not that I actually would wantHaHa). You undoubtedly put a entire new spin for a topic thats been written about for years. Excellent stuff, just wonderful! 542647
324080 620015Wahhhh,!! I dnt believe its food thats creating her tummy groww!!|tiitaBoo| 71815
16500 149971I dugg some of you post as I cogitated they were very beneficial invaluable 495672
693136 501129Yeah bookmaking this wasnt a risky decision outstanding post! . 482246
587465 362765Hey, are you having issues with your hosting? I necessary to refresh the page about million times to get the page to load. Just saying 158457
605242 649495Nice read, I just passed this onto a colleague who was performing slightly research on that. And he just bought me lunch since I identified it for him smile So let me rephrase that: Thank you for lunch! 582056
19349 487213Good post. I be taught 1 thing far more challenging on totally different blogs everyday. It will all the time be stimulating to learn content from other writers and apply slightly one thing from their store. Id desire to use some with the content material on my weblog whether you dont mind. Natually Ill give you a hyperlink on your net blog. Thanks for sharing. 27014
607453 228085Basically wanna input that you have a extremely good internet site , I enjoy the pattern it truly stands out. 787067
206742 224469Ill do this if want to as significantly as I hope that is not too far off the track. 25189
290262 828518I want seeking at and I believe this internet site got some really valuable stuff on it! . 671689
77658 274715I saw two other comparable posts although yours was the most beneficial so a good deal 969736
277860 95776Fantastic post, I conceive blog owners ought to acquire a great deal from this web weblog its real user pleasant. 215728