Pex (Program EXploration) is an assistant to the programmer.Pex takes test-driven development to the next level. Pex analyzes .NET programs. From a parameterized unit test, it automatically generates unit tests cases with high code coverage. In addition,when a generated test fails, it suggests to the developer how to fix the bugs.
- With Pex, you can write parameterized unit test methods and leave to Pex the task of deciding which input is relevant to cover the code (or find bugs). Actually, parameterized unit tests are nothing but specifications. Pex integrates ‘naturally’ with existing unit test framework (VSTS, NUnit, MbUnit, etc…) by providing a set of custom attributes to tag Pex classes and tests.
- Call Pex directly from Visual Studio to start exploring the parameterized unit tests.
- Pex runs the parameterized unit tests with different input values. Pex monitors the execution and figures out why the program executed the way it did. This is represented as a boolean function over the test parameters. Pex then uses a constraint solver to compute new parameter values that make the program execute in a different way.
- From the parameterized unit tests, Pex generates classic unit tests that can be re-executed without Pex. Pex also tags the generated tests with additional information using attributes (for tools) and xml documentation (for humans).
- While exploring parameterized unit tests, Pex explicitly looks for program errors such as index out of bound or failing user assertions. Pex reports dynamically detected errors in the code.
- Sometimes Pex can automatically fix bugs! When a test fails, Pex traces back the involved values. Pex suggests additional checks to prevent the failure from happening again. Those checks are argument or invariant validation.
- Pex summarizes all the possible fixes in a prioritized table with quick preview.
- Pex integrates generated tests automatically inside the test project. Pex also avoids duplicate tests and recycles obsolete tests.
- Pex comes with a command line tool to execute any assembly containing Pex tests. Great for automation!
- Pex generates detailed HTML reports about the exploration process. The reports contains details about each generated tests, path conditions, suggested fixes, etc…
- Pex generates code coverage reports for each test.
- Pex has a built-in support for mocking interfaces and virtual methods. Pex generates the return values of mocked methods just like it generates test input for parameterized unit tests.