Geeks With Blogs

@onefloridacoder

News
John Smith's Blog Keeping the fun machine running one nickel at a time
Pex has had two updates, one since I first used it, and one after I finished using it.  Here’s the release notes for the latest build that dropped on 5/1/2009.  Fresh install, and rewinding back through the project I had referenced in my first post.  This time I need to build a different project that doesn’t reference my day job and also how well things work with xUnit.  imageThe install was perfect again, no issues with that so far.  Here are the release notes, and a few steps setting up a new project.  I’m just going to start a new project and start from scratch and buzz through the same examples I worked through previously.  Here’s the new project setup. 

 

Now that I’ve got a new project to work against, we can generate the Pex test project and ask Pex to get busy.  First we’ll ask Pex to create a new xUnit test project.  Right-clicking the Facade project exposes the context menu, we’ll choose “Create Parameterized Unit Test Stubs”, aka PUTs. 

 

 

 

 

 

This gives us the following dialogs to set our project properties.   I’ll leave the blanks blank, those exist to filter the namespace, type name, and method names you want to filter for the project under test. We want all of them, so they’ll be left blank. 

A variation on this is if you open the context menu inside the class file.  The filter fields are filled in for you to limit Pex’ interaction.

 imageimage 

 

 

 

 

 

 

 

 

 

 

 

Here are the settings I’ve chosen, I’m going with xUnit this time around.

image

 

 

 

 

 

 

 

imageThe “Settings…” dialog is where I tell Pex that for all unit tests created, each will have the PexTest suffix.

"Mark all test results Inconclusive by default" - This setting will add the Assert.Inconclusive() assertion at the bottom of the test method which is the default for all Visual Studio unit tests when they are generated in the IDE.

"Globally qualify all types" - This setting will prefix all fields in the test class with global qualifier.

"Use Code Patterns" - Pex utilizes many different code patterns which are beyond the scope of this document. You can find them in this document's appendix.

"Generate Stubs file for project under test" - The Stubs Framework utilized by Pex is explained by one of the authors here.

We click OK on the settings dialog.  We click OK on the main dialog, and Pex shows us the dialog pictured below.  We’re getting a unit test project called …\ProjectName.Tests (plural suffix);  now is your only chance to move this project around.  If you like to keep your unit test libraries somewhere else besides the project it’s testing move it to that place.  The MSTest dialog gives us a singular suffix.  So if you have both, this might help you keep them apart.  Hopefully they will allow us to (re)label them in future versions of Pex.

 image

Click OK.

If Pex can’t find your test runner, you’ll be prompted for the location.

image 

 

 

 

 

 

 

 

 

Here are the new pieces Pex has added.

image

 

A few things to notice here. We get one Pex class for each of our classes so the test methods are segregated neatly. The point to make here is to get everything neat before you generate the test project.  Also, notice the suffix, "PexTest". We can't rename the class library suffix, so I chose to rename the class files so I know by looking at the project members which classes are mine, and which ones were generated by Pex. Also, the stub file mentioned previously is generated for us.

image

 

 

 

 

 

 

 

 

 

Here’s what Reflector can show us about what was created as well, the crunchy layer looks pretty much identical to the Crunchy layer.

image

namespace PeanutButter.Business.Facade.Creamy
{
    /// <summary>This class contains parameterized unit tests for CreamyLayerManager</summary>
    [PexClass(typeof(CreamyLayerManager))]
    [PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
    [PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
    public partial class CreamyLayerManagerPexTest
    {
        /// <summary>Test stub for Add(!!0)</summary>
        [PexGenericArguments(typeof(int))]
        [PexMethod]
        public void Add<T>([PexAssumeUnderTest]CreamyLayerManager target, T entityToAdd)
        {
            // TODO: add assertions to method CreamyLayerManagerPexTest.Add(CreamyLayerManager, !!0)
            target.Add<T>(entityToAdd);
        }
 
        /// <summary>Test stub for Remove(!!0)</summary>
        [PexGenericArguments(typeof(int))]
        [PexMethod]
        public void Remove<T>(
            [PexAssumeUnderTest]CreamyLayerManager target,
            T entityToRemove
        )
        {
            // TODO: add assertions to method CreamyLayerManagerPexTest.Remove(CreamyLayerManager, !!0)
            target.Remove<T>(entityToRemove);
        }
 
        /// <summary>Test stub for Update(!!0)</summary>
        [PexGenericArguments(typeof(int))]
        [PexMethod]
        public void Update<T>(
            [PexAssumeUnderTest]CreamyLayerManager target,
            T entityToUpdate
        )
        {
            // TODO: add assertions to method CreamyLayerManagerPexTest.Update(CreamyLayerManager, !!0)
            target.Update<T>(entityToUpdate);
        }
    }

 

The only Source Analysis violation are related to moving the using statements inside the namespace declaration and the adding the method arguments to the summary block. Source and Code Analysis compliance was one of the latest features added to the Pex release in use.

Notice the method decoration "[PexMethod]" This method won't be visible to the xUnit test outline since unit tests are reference by the FactAttribute. If it would have been decorated with "[Fact]" it would.  Also notice Pex methods are parameterized (PUTs) tests.  The xUnit methods will be generated from, and by, the PUTs.

The PexMethod(s) will be used during the Pex Exploration we will step through now.  Right-clicking the test project exposes the Pex Exploration menu item which starts the exploration process.

 

image

 

 

 

 

 

 

 

 

Pex Exploration finishes and the Pex Explorer tells us we have some problems - all of my methods are throwing NotImplementedExceptions” - nice.  image 

 

 

 

 

 

 

 

 

 

 

I’ll stop here, fix my code and pick-up with an Exploration exercise to allow Pex to do something meaningful with my test project.

 

Until then.

Posted on Saturday, May 16, 2009 2:37 PM | Back to top


Comments on this post: Flex Your Pex (Part 1)

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Hey John,

Thanks for the tutorial, it made things much easier for me to understand.
Left by vegetarian dishes on Nov 29, 2010 1:59 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
I’ll stop here, fix my code and pick-up with an Exploration exercise to allow Pex to do something meaningful with my test project.
Left by nike air jordans on Jan 07, 2011 3:35 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for presenting an useful tutorial. It seems very useful for us. Great post.
Left by Quick cash loans on Feb 01, 2011 12:26 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
I am the frequent visitor of this website.I had already added this blog to my favorites.Thank you for sharing this!
Left by Batch PDF Converter on Feb 18, 2011 5:09 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
There is a site named pex for fun.made by microsoft. IT gives code puzles and you solve it. Its really fun. http://www.pexforfun.com/
Left by Yale Alarm on Feb 21, 2011 9:35 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
allow Pex to do something meaningful with my test project.http://www.lpdedicated.com/
Left by Dedicated Server on Feb 23, 2011 3:50 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for sharing such a great post as it's very interesting and informative.
Left by Seo services in India on Mar 03, 2011 11:23 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for presenting an useful tutorial. It seems very useful for us. Great post.
Left by flour mill on Mar 08, 2011 10:14 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Pex Exploration finishes and the Pex Explorer tells us we have some problems - all of my methods are throwing NotImplementedExceptions” - nice.
Left by etui cuir nokia c7 on Mar 23, 2011 12:50 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Pex generates test suites with high code coverage. It finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage.
Left by Fast cash on Mar 28, 2011 1:24 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for walking through this, I don't think i would have figured it out otherwise!
Left by pop up canopies on Apr 18, 2011 7:02 AM

# hello
Requesting Gravatar...
I have just recently found your blog and absolutely love the posts. Thank you, thank you. I am still .NET programming but can't wait to try these things in Ruby and it is a great help to see such clear examples. kids apron
Left by Kids aprons on Jul 18, 2011 5:52 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
This is a very useful post! I started to read your blog several months ago and truing to visit every single week. Thank you for sharing such a useful info.Regards,
Left by Costa Rica Real Estate on Jul 20, 2011 11:19 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for every other wonderful article. The place else may anybody get that kind of information in such a perfect means of writing? I’ve a presentation next week, and I’m at the search for such information.
Left by free cell phone spy on May 22, 2012 3:57 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for walking through this, I don't think i would have figured it out otherwise!
Left by all kitchenware on Jan 06, 2013 11:46 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Very nice article in this post.
Left by Laptops buy on Jan 06, 2013 11:47 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
very nice and clearly write on this blog.
Left by all home theater buy on Feb 15, 2013 8:31 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks for walking through this, I don't think i would have figured it out otherwise!
Left by Tisu Majakani on Feb 27, 2013 11:23 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Super like this information, very useful.
Suplemen Fitness
Espresso Coffee Maker
Left by Amor on Apr 18, 2013 8:30 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Thanks! this valuable information is worth everyone's attention. When can I find out more?
harga laptop
konveksi jaket
Left by Anne on Apr 29, 2013 9:26 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
I simply stumbled upon your website and wanted to say that I have really enjoyed reading your blog post.
modifikasi ninja
teknik sipil
Left by Amura on May 12, 2013 7:20 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
I simply stumbled upon your website and wanted to say that I have really enjoyed reading your blog post.
control engineering
Left by Akelo on May 12, 2013 10:47 PM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
I am really impressed by this blog!Very clear explanation of issues is given and it is open to everyone.
It contains true and fair information.
Your website is very useful Obat diabetes
Left by Obat Kuat on May 13, 2013 12:48 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
Very good post. Something which is very close to our heart.
You always have a way of making it so easy to follow your thoughts and what you’re sharing with us.
Thank you very much.Obat Kuat
Left by samurai on May 13, 2013 12:49 AM

# re: Flex Your Pex (Part 1)
Requesting Gravatar...
This is very interesting article.
Your article affects a lot of "burning" issues in our society.
It is impossible to be indifferent to these challenges.
There are many articles on the web on this particular point,
but you have captured another side of the topic.
Obat Kuat
This post gives the light in which we are able to observe the reality.
Very professional.
Left by TRIOMAN on May 14, 2013 1:52 AM

Your comment:
 (will show your gravatar)
 


Copyright © onefloridacoder | Powered by: GeeksWithBlogs.net | Join free