Take the 2-minute tour ×

I love the idea of Pex - autogenerating unit tests through static code analysis - but the tests that are actually generated by the tool are horrible, ugly, tightly coupled to Pex modules, difficult to read and understand etc.

Is a tool like that really suitable (in its current state) for use in an enterprise environment, where the emphasis must be on ease of maintenance?

Or have I misunderstood the intended use of Pex?

share|improve this question
In Visual Studio 2012 Pex is replaced (in part) by Fakes msdn.microsoft.com/en-us/library/hh549175.aspx –  Peter Ritchie Sep 6 '12 at 16:25
add comment

4 Answers

Indeed, you have misunderstood the intended use.

Pex is a white-box testing tool. It generates test cases based on the analysis of the code it should test. The reason for this is to detect and test edge cases. So basically, you shouldn't even change the auto-generated tests.

Your normal unit-tests can't be replaced by Pex. It's just an additional tool.

share|improve this answer
add comment

Pex is very useful for testing complex algorithms that do not rely on anything external. For example, it will not help you find edge cases in SQL statements or file access. However, for finding edge cases and increasing code coverage, it is extremely useful in addition to your normal unit tests.

share|improve this answer
add comment

This seems a subjective question...

I'd say that yes, tests written in a given framework/API are often tightly coupled to that framework. Pex's intention is not to generate "readable" tests, it's to ensure code coverage for a given set of constraints. If that's valuable to your product, then it's suitable - and certainly I'd wager that for a given team and a given codebase, this will provide value.

Every enterprise is different, but it's the product and its code that dictates the suitability of a testing tool. I would suggest that the thing to question is the value of Pex for a given codebase, regardless of the organisation in question.

share|improve this answer
add comment

I have used pex in a large financial institution and would recommend its use, but only for a very specific case. I think pex is good at what it does (as described elsewhere here, white box tests to find edge cases), but the tests do not have significant longevity as they are very tightly coupled.

Basically pex is great at generating coverage. If you have no tests and want some fast, use Pex. BUT THEN I recommend that instead of using it again you enforce standards for new code to meet an agreed coverage metric with hand written tests.

In this way the fragile tests from pex get replaced over time with tests that are more flexible and of a higher quality.

share|improve this answer
add comment

Your Answer


