Can Pex automatically detect overflow / type overflow conditions?

Suppose there is such a method (C #):

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

If the sum does not fit into the int data type, this is probably the error that costs the unit test. Can Pex identify such errors and generate unit tests for these?

+6
source share
1 answer

Yes, it's very well. When introducing Pex, they will often use the error found in the binary sorting procedure of the Java library, where it will overflow for very large arrays when looking for a new middle. A related set of errors are errors in a leap year, and they will usually use a function from one of Microsoft's own products (Azure?), Which displays one of them in the wild.

Pex picks up many different types of errors, including overflows, submenus, null links, invalid arguments, and even any custom exceptions that you throw into your application. I highly recommend reading some of the tutorials started and then combining Pex with code contracts to make your life a lot easier in the long run.

+5
source

Source: https://habr.com/ru/post/927672/


All Articles