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?