Pex - Automated Whitebox Testing for .NET : PexAssume

PexAssume


Static class to express assumptions, i.e. a precondition, in parameterized unit tests. The methods of this class can be used to filter out undesirable test inputs.

If the assumed condition does not hold for some test input, a PexAssumeFailedException is thrown, which will cause the test to be silently ignored.

Example

The following parameterized test will not consider j=0.

public void TestSomething(int i, int j) {
     PexAssume.AreNotEqual(j, 0);
     int k = i/j;
     ...
}

Remarks


The code above is almost equivalent to
     if (j==0)
          return;
except that a failing PexAssume results in no test cases, whereas in the case of an if-statement, Pex would generate a separate test case to cover the then-branch of the if-statement.

PexAssume also contains specialzed nested classes for assumptions on string, arrays and collections.

See Also


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