BT

Pex Automated Exploratory Testing for .NET

by Al Tenhundfeld on Jul 15, 2008 |
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.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Pex 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 appdevchronicles.blogspot.com/2008/07/pex-test-....

Best regards,

Alexander Nowak

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT