Question

Suppose there is a method like this (C#):

public static int Add(int x, int y)
{
    return x + y;
}

If the sum does not fit into the int data type it is probably an error situation which is worth a unit test. Is Pex able to identify such errors and generate unit tests for those?

Was it helpful?

Solution

Yes, it's very good at it. When introducing Pex they will frequently use the bug found in the Java library's binary sort routine where it would overflow for very large arrays when finding the new midpoint. A related set of bugs are the leap year bugs and they will commonly use a function from one of Microsoft's own products (Azure?) which displayed one of these in the wild.

Pex catches many different classes of bugs including Overflows, Underflows, Null References, Invalid Argument, and even any custom exceptions you throw in your application. I highly recommend reading the some of the getting started guides and then combine Pex with Code Contracts to make your life much easier in the long run.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top