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
xUnit.Net ,
MSTest ,
MbUnit ,
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.
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

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.