RSS Feed

Microsoft Pex – Automated Unit Testing

Microsoft Pex isa Visual Studio add in, which enables code analysis on the runtime. The great fact about it, is  the ability to generate tests automatically. I analyzed my small project with it check out the results.

 

Automated Tests

image

 

While analyzing you can watch whole process in Pex Explorer. As you can see only two of my classes passed the tests. Rest, well they are in red and that’s a bad sign. The Pex created all the tests by itself.

 

image

 

On this image you can see all the test cases generated by Pex for my Task class. Lets take a closer look at my TaskBin class and CreateFromString Method.

 

image image

 

Left image shows all the performed tests and shows, which failed or passed. On the right image, you can analyze data on which the test was run. You can clearly see on which string the test failed and, which was ok.

Values used for tests are generated based on the if statements,  assertions, and operations that can throw an exception. The code is first analyzed, and then the values are generated.

After the tests are generated you can save and store them for later use.

 

Suggestions

image

 

After the analyze process, Pex also makes suggestions with fixes to encountered problems.

 

Integration with Various Unit Test Frameworks

As a Microsoft product Pex is not only using the MsUnit tests. You can run it with :

and more.

I have used the NUnit.

 

The Future of Unit Testing ?

This is quite a nice tool. While writing tests you have to write a lot of code. Pex frees us up from this task,  at least a bit. I think that Pex will be a useful addition and will generate simplest tests. Developer will be able to focus his attention on more complex tests.

Do you think that the whole process of Unit Testing will be automated?

Advertisements

2 Comments on “Microsoft Pex – Automated Unit Testing”

  1. ayoussif says:

    Pex Problem with MyGeneration Code Generator

    ——————————————————————————–

    I am new to PEX, i Have an application which have multiple layers, and I am using Code generator (MyGeneration)to create my DAL, when I tried to use PEX it always exceeds the bounds and always set the object to null, I think the problem comes when it set properities in the Object that should never changes(Default values),


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s