Pex - Automated Whitebox Testing for .NET : Pruning by Assumptions

Pruning By Assumptions

Pex provides a static class to express assumptions, i.e. pre-conditions, in parameterized unit tests, PexAssume.

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


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


The code above is almost equivalent to

     if (j==0)
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 specialized nested classes for assumptions of string, arrays and collections.

See Also

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