Pex - Automated Whitebox Testing for .NET : Test To Code Binding

Test To Code Binding


Pex lets specify the code under test for a particular assembly or fixture, i.e. the test to code binding.

This information is very interesting in many aspects:

  • for you,
    • it expresses explicitly the intent of the developer/tester,
    • it can be used through the command line to filter tests to run,
  • for Pex,
    • focus it's search on the code under test,
    • instrument the code under test,
    • tell the wizard where to add generated files,
    • provide coverage numbers with respect to the code under test,
  • for other tools
    • e.g. which tests to rerun after code has changed.

Assembly Under Test

The PexAssemblyUnderTest attribute can be used to specify that an assembly MyAssembly is tested by the current test project:

[assembly: PexAssemblyUnderTest("MyAssembly")]


Type Under Test


The type under test for a given fixture can be set through one of the PexClass constructors:

[TestClass, PexClass(typeof(Foo))]
public partial class FooTestClass
{ ... }



[assembly: PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException))]



[assembly: PexAllowedContractRequiresFailureAtTypeUnderTestSurface]

(c) Microsoft Corporation. All rights reserved. pex Wiki Documentation 0.93.50813.0