Attribute glossary

Attributes by namespace


This attribute asserts that the governed value cannot be null. It can be attached to:

  • a parameter of a parameterized test method

    // assume foo is not null
    public void SomeTest([PexAssumeNotNull]IFoo foo, ...) {}
  • a field

    public class Foo {
       // this field should not be null
       public object Bar;
  • a type

    // never consider null for Foo types
    public class Foo {}

It can also be attached to a test assembly, test fixture or test method; in this case the first arguments must indicate to which field or type the assumptions apply. When the attribute applies to a type, it applies to all fields with this formal type.


This attribute marks a class that contains explorations. It is the equivalent of the MSTest TestClassAttribute (or the NUnit TestFixtureAttribute). This attribute is optional.

The classes marked with PexClass must be default constructible:

  • publicly exported type
  • default constructor
  • not abstract

If the class does not meet those requirements, an error is reported and the exploration fails.

It is also strongly advised to make those classes partial so that IntelliTest can generate new tests that are part of the class, but in a separate file. This approach solves many problems due to visibility and is a typical technique in C#.

Additional suite and categories:

[TestClass] // MSTest test fixture attribute
[PexClass(Suite = "checkin")] // fixture attribute
public partial class MyTests { ... }

Specifying the type under test:

[PexClass(typeof(Foo))] // this is a test for Foo
public partial class FooTest { ... }

The class may contain methods annotated with PexMethod. IntelliTest also understands set up and tear down methods.


This attribute provides a type tuple for instantiating a generic parameterized unit test.


This attribute marks a method as a parameterized unit test. The method must reside within a class marked with the PexClass attribute.

IntelliTest will generate traditional, parameterless tests, which call the parameterized unit test with different parameters.

The parameterized unit test:

  • must be an instance method
  • must be visible to the test class into which the generated tests are placed according to the Settings Waterfall
  • may take any number of parameters
  • may be generic


public partial class MyTests {
     public void MyTest(int i)
     { ... }


More information


This attribute can be set at the assembly level to override default setting values for all explorations.

using Microsoft.Pex.Framework;
// overriding the test framework selection
[assembly: PexAssemblySettings(TestFramework = "MSTestv2")]


This attribute specifies an assembly that is being tested by the current test project.

[assembly: PexAssemblyUnderTest("MyAssembly")]


This attribute is used to specify an assembly to be instrumented.


using Microsoft.Pex.Framework;

// the assembly containing ATypeFromTheAssemblyToInstrument should be instrumented
[assembly: PexInstrumentAssembly(typeof(ATypeFromTheAssemblyToInstrument))]

// the assembly name can be used as well
[assembly: PexInstrumentAssembly("MyAssemblyName")]


This attribute tells IntelliTest that it can use a particular type to instantiate (abstract) base types or interfaces.


public void MyTest(object testParameter)
     ... // IntelliTest will consider types A and B to instantiate 'testParameter'


If this attribute is attached to a PexMethod (or to a PexClass, it changes the default IntelliTest logic that indicates when tests fails. The test will not be considered as failed, even if it throws the specified exception.


The following test specifies that the constructor of Stack may throw an ArgumentOutOfRangeException:

class Stack {
  int[] _elements;
  int _count;
  public Stack(int capacity) {
    if (capacity<0) throw new ArgumentOutOfRangeException();
    _elements = new int[capacity];
    _count = 0;

The filter is attached to a fixture as follows (it can also be defined at the assembly or test level):

class CtorTest(int capacity) {
  Stack s = new Stack(capacity); // may throw ArgumentOutOfRangeException


More information


More information


More information

Got feedback?

Post your ideas and feature requests on Developer Community.