Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Pex White-box Test Generator Updated

Pex White-box Test Generator Updated

This item in japanese

Microsoft Research has released a new version of Pex, an automated white-box testing library for .NET. Pex v0.11 adds support for Delegates as Parameters, a new Exception Tree View, Stubbed Events, and Recursive Stubs. This release fixes an issue with incorrect registration of the Stubs Visual Studio Add-in, and it updates Pex to reference the latest Code Contracts release.

Right from the Visual Studio code editor, Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Pex performs a systematic analysis, hunting for boundary conditions, exceptions and assertion failures, which you can debug right away. Pex enables Parameterized Unit Testing, an extension of Unit Testing that reduces test maintenance costs.

Pex v0.11.40421.0 can be downloaded from MS Research. This release requires the OpenMP C++ runtime. This runtime is installed by default on a machine with Visual Studio or can be downloaded separately.

Delegate As Parameters: Pex now understands Parameterized Unit Tests that take delegates as parameters. Pex will automatically generate a delegate instance and its behavior: if the delegate returns a value, Pex will generate a new symbolic value for it, track its use, and then generate different values depending on the program behavior.

When executing Pex on Test, Pex will generate a Func which ‘asks’ Pex to choose the returned int (it uses PexChoose under the hood). Therefore, for each call to that delegate, Pex has the liberty to return a diferent value. Based on how it is used, Pex will generate different values to increase coverage. In this case, Pex ‘chooses’ to return 123 on the first call, which is exactly what we need to cover the exception branch.

Pex Explorer: Exception Tree View:

We have started to work on improving the experience when applying Pex to a large number of explorations. To this end, a new window called Pex Explorer will show various views over the events produced by Pex. The Exception Tree View provides the tree of exception types that Pex found. This is really helpful to quickly drill through the (really) bad exceptions first.

Pex Explorer: Contract Failures Tree View: If Code Contracts are being used, Pex also provides a specialized view to sort the contract failures kind.

Events in Stubs: Stubs now support events:the stub simply expose the backing delegate fields (which hold the event delegate)as a public fields. As a result, one can clear, set, and invoke the event as any other member.

Recursive Stubs: Another common feature of mock/stub frameworks is to support nested invocation of members. Stubs now lets you recursively invoke property getters. Instead of assigning the property getter delegate, you can use new helper methods ending in ‘AsStub’ that take care of allocating the nested stub, assigning it to the property getter and returning it.

Rate this Article