Pex - Automated Whitebox Testing for .NET : Instrumented Assemblies and Types

Instrumented Assemblies and Types


Pex generates test inputs by monitoring executions of .Net applications. Pex requires the user to specify which parts of the code it should monitor. When a test (indirectly) calls an uninstrumented method, Pex might give a Uninstrumented Method Called warning.

Pex can only reason about the code it monitors. It is important to understand the trade-offs between monitoring enough code to capture the behavior of your application and not too much to avoid slowing down the execution too much:
  • monitoring requires an 'heavy duty' code instrumentation which increase jitting time and degrades performance. For example, if the List<> class is instrumented, all your collections will be monitored!
  • the more things we monitor, the more constraints we gather and hand to our constraint solver. This will increase exploration time.
    • Pex also provides an extended instrumentation mode that makes the code mockable. In that mode, method or constructor calls cannot be 'hijacked', constants can be replaced etc... This mode is even more impactfull on performance.
  • Pex does not know about things that happen in code that is not monitored. Therefore, it cannot generate test cases that thoroughly exercise code paths in unmonitored code.
  • The assemblies/types to instrument can be set through attributes and the command line. The default behavior is specify each assembly/type to instrument. However, it is possible provide wildcards such as * to specify all assemblies/types.

Attributes



Instrumented By Default


The following assemblies/types are instrumented by default for your convenience:

  • the assembly containing the Pex classes (You can disable this using the command line option /a-).
  • the assertion and assumption types of your test framework.

Native Code


Pex cannot instrument native (x86) code. However, Pex has a set of mechanisms to describe the behavior of native code by Code Substitutions.

Command Line


/instrumentedassemblies:<string> where <string> is a semi-column separated list of assembly names,

Extensibility


If you want to implement your own attributes to specify assemblies or types to instrument, you simply need to create attributes that inherit from PexInstrumentAssemblyAttributeBase for assemblies and PexInstrumentTypeAttributeBase for types.

See Also

PexInstrumentAssemblyAttribute, PexInstrumentNamespaceAttribute, PexInstrumentTypeAttribute, PexInstrumentMarkedByAttribute
(c) Microsoft Corporation. All rights reserved. pex Wiki Documentation 0.93.50813.0