InfoQ

News

Pex Automated Exploratory Testing for .NET

Posted by Al Tenhundfeld on Jul 15, 2008 11:48 PM

Community
.NET
Topics
Unit Testing
Tags
MbUnit,
MSTest,
xUnit.Net,
TDD
Pex is a white-box test generation tool from Microsoft Research. Instead of hand-writing a separate test case for each execution path within a given method, a developer can write a single parameterized test method, which Pex will use to generate a suite of standard MS Test unit tests to exercise paths within the target method. Pex analyzes .NET code, instruction by instruction, interpreting what actions the code is performing, and then, "in a fully automatic way, Pex computes relevant test inputs that trigger the corner cases of the code."
Given a hand-written parameterized unit test, Pex analyzes the code to determine relevant test inputs fully automatically. The result is a traditional unit test suite with high code coverage. In addition, Pex suggests to the programmer how to fix bugs.
Pex does not lessen the need for developers to write unit tests that define and cover the intended behavior of a method, ensuring the API and functionality meet the essential use case or user story requirements. However, Pex can be used as an additional means to ensure that tests adequately cover the implementation code. This automated exploratory testing can be especially useful for identifying unintended behavior and errors within a method.

As with most generation tools, Pex works best when used with certain conventions. Keeping methods short and testable is design principle within TDD, and this principle will make Pex's generated tests more understandable as well. Pex can also be an aid in achieving this design goal, i.e., if Pex generates numerous complex tests for a method, the method might be a candidate for refactoring. Pex also works best when methods have primitives as parameters, instead of custom objects.

By default, Pex integrates with Visual Studio 2008 and MSTest, but Pex extensions can be downloaded to support NUnit, MbUnit or xUnit.Net. Pex also builds on the Extended Reflection managed profiling API to facilitate integration of monitoring applications.

Note that Pex is currently a prototype from Microsoft Research and not a supported Microsoft product. Pex should not be used as the primary means of writing unit tests, but its automated test generation can help cover edge cases efficiently.

1 comment

Reply

Pex by Alexander Nowak Posted Jul 24, 2008 12:43 AM
  1. Back to top

    Pex

    Jul 24, 2008 12:43 AM by Alexander Nowak

    Hello, Very sharp and clear summary of Pex. Recently I started "exploring" Pex and I fully subscribe to your analysis regarding the use of Pex. I worked out some (academic) test cases where I tried out Pex. If you like you can read about at http://appdevchronicles.blogspot.com/2008/07/pex-test-case-1.html. Best regards, Alexander Nowak

Exclusive Content

Typemock: Past, Present and Future

Eli Lopian of Typemock answers a few questions on Typemock origins and where Typemock is headed.

Agile in Practice: What Is Actually Going On Out There?

Scott Ambler talks about actual data resulting from surveys made during 2006-2008, showing how Agile is perceived and implemented within organizations.

Building Smart Windows Applications

From QCon 2008, Daniel Moth presents on using Visual Studio 2008 and .NET 3.5 to create compelling rich Windows applications.

Joshua Kerievsky about Industrial XP

Joshua Kerievsky, founder of Industrial Logic, talks about Industrial Extreme Programming which extends XP by including practices dealing with management, customers and developers.

Jeff Barr Discusses Amazon Web Services

Amazon Web Services (AWS) Evangelist Jeff Barr discusses SimpleDB, S3, EC2, SQS, cloud computing, how different Amazon services interact, origins of AWS, AWS globalization and the March AWS outage.

More Than Just Spin (Up) : Virtualization for the Enterprise and SaaS

Cloud services have helped bring virtualization to the forefront. Its full power however, also includes other benefits such as high availability, disaster recovery, and rapid provisioning.

Ruby Beyond Rails

John Lam talks about his path to dynamic languages, some of the problems of making IronRuby run fast, and how the DLR helps with implementing languages.

VMware Infrastructure 3 Book Excerpt and Author Interview

VMware Infrastructure 3: Advanced Technical Design Guide and Advanced Operations Guide provides a wealth of practical insights into setting up virtualization in todays corporate environments.